slotscheck icon indicating copy to clipboard operation
slotscheck copied to clipboard

Warn if inheriting from non-slotted protocol in slots-required mode

Open ariebovenberg opened this issue 1 year ago • 1 comments

(A bit of an obscure edge case, but worth documenting for future reference.)

The require-subclass mode warns of any classes which could be slotted, but are not.

class A(int):  # slots-required error triggered because A cloud be slotted, but isn't
    ...

class B(A):  # no slots-required error because B cannot be slotted (because one of its superclasses isn't)
    ...

However, protocols complicate things a bit:

class MyProto(Protocol):  # no slots-required error because protocols are not concrete classes
    ...

class C(MyProto):  # no slots-required error because one of its superclasses has no slots.
    ...

In the last case, we might want to emit a warning that C could be slotted if its protocol is. In the current situation, C is more-or-less silently allowed to not have slots. Note that this problem is not present in ABC because they are meant to be inherited from and do trigger slots-required themselves.

ariebovenberg avatar Jan 02 '23 09:01 ariebovenberg