Skip to content

E0308: bytes not recognized after encode #3599

@bitozoid

Description

@bitozoid

Steps to reproduce

  1. File test_bytes.py
class Sample:

    # warns about E0308: invalid-bytes-returned
    def __bytes__(self):
        return "hey".encode('utf-8')


# will print <class 'bytes'>
print(type(bytes(Sample())))
  1. pylint it.
$ python test_bytes.py
<class 'bytes'>

$ pylint test_bytes.py
************* Module test_bytes
test_bytes.py:1:0: C0114: Missing module docstring (missing-module-docstring)
test_bytes.py:1:0: C0114: Missing module docstring (missing-module-docstring)
test_bytes.py:1:0: C0115: Missing class docstring (missing-class-docstring)
test_bytes.py:4:4: E0308: __bytes__ does not return bytes (invalid-bytes-returned)
test_bytes.py:1:0: R0903: Too few public methods (1/2) (too-few-public-methods)

-------------------------------------
Your code has been rated at -10.00/10                                    

Current behavior

I get an E0308.

Expected behavior

Not to get an E03008.

pylint --version output

pylint 2.5.2
astroid 2.4.1
Python 3.7.7 (default, Mar 23 2020, 11:12:08) 
[GCC 9.3.0]

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions