-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
typing.Protocol classes should probably be ignored #130
Comments
Good find, I agree! A special case was needed for A nuance here is that it is possible to inherit from protocols, and then we do want to enforce them class A(Protocol):
foo: int
class B(A): # using A as explicit base class requires slots there
__slots__ = ...
foo: int
bar: str |
require-subclass option now doesn't flag protocol classes (#130)
version 0.16.2 is out, which should fix this. Feel free to re-open if it doesn't work for you. |
Hmm, well it does work when from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing_extensions import Protocol
else:
Protocol = object
class MyProtocol(Protocol):
... Though it's probably impossible for slotscheck to handle something like this without introducing some complex static analysis. Oh well, I suppose we can just make Thanks for addressing this so quickly though! |
You can always add a specific ignore regex, but that would be quite cumbersome. Something like #71 would be useful in your case, I think. |
Currently,
slotscheck
is marking classes that inherit fromtyping.Protocol
as regular classes, and reports missing slots. However protocol classes are usually not used for actual inheritance, and defining__slots__
on them would mean a type-checker would be checking for presence of__slots__
when determining whether a type can be downcasted to given protocol class.Here's an example of this:
The
DecoratorFunction
class shouldn't be slotted, and slotscheck probably shouldn't enforce the presence of__slots__
there.The text was updated successfully, but these errors were encountered: