Skip to content

__slots__ and protocols don't work right for issubclass and typevar bounds #11884

Closed
@A5rocks

Description

@A5rocks

cc @sobolevn since you've been doing stuff here

Bug Report

Slots become part of a interface with protocols, they shouldn't be.

To Reproduce

import typing

@typing.runtime_checkable
class Foo(typing.Protocol):
    __slots__ = ()


class Bar:
    pass

_T = typing.TypeVar("_T", bound="Foo")


def foo(f: _T) -> _T:
    return f

print(issubclass(Bar, Foo))
print(isinstance(Bar(), Foo))
foo(Bar())

Expected Behavior

At runtime this prints:

True
True

So issubclass is allowed, and I don't see why the TypeVar bounds shouldn't be.

Actual Behavior

main.py:17: error: Only protocols that don't have non-method members can be used with issubclass()
main.py:17: note: Protocol "Foo" has non-method member(s): __slots__
main.py:19: error: Value of type variable "_T" of "foo" cannot be "Bar"
Found 2 errors in 1 file (checked 1 source file)

Your Environment

mypy playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions