Skip to content

bytes(obj) rejected even when obj implements __bytes__ #3989

@bmerry

Description

@bmerry

Sample code:

#!/usr/bin/env python3

class A(object):
    def __bytes__(self) -> bytes:
        return b'An A'

print(bytes(A()))

Output from mypy 0.521, Python 3.5.2:

test.py:7: error: No overload variant of "bytes" matches argument types [test.A]

Looking in typeshed, it has this overload:

class bytes(ByteString):
    @overload
    def __init__(self, o: SupportsBytes) -> None: ...

which doesn't seem to be matching.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions