-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Subclassing a dataclass protocol incorrectly flags not implementing all required members #6675
Comments
I'm not sure that it makes sense to allow My inclination is to change pyright to detect this combination and report it as an error so it is disallowed. I would want to consult with the broader typing community before doing so. I'd also like to understand your intent in trying to combine these two concepts. Why are you using protocols here? This seems like a misuse of the concept. |
FWIW, mypy issues the same error as pyright in this case. But I'm guessing that's because the mypy authors (like me) didn't contemplate anyone every trying to use |
Python lets me do weird things, so I try to do those things and see what breaks. It's a weird combination but I make prolific use of dataclasses. I don't remember the last time I wrote a real I personally prefer having pyright agree with what happens at runtime. But |
I was switching to a protocol to try to get round the issue described in #2601 with some classes directly implementing the protocol, others indirectly. |
Thanks for the additional information. The issue goes beyond the As I said above, I don't think it makes sense to use For now, I'm going to close this issue without making any changes to pyright. I think it's arguably doing the right thing in the face of a misuse of |
When subclassing a protocol class that has been annotated with
@dataclass
pyright flags an error that members are not implemented. These members are implicitly implemented by the subclass/dataclass annotation. Subclassing from a protocol with an__init__
that assigns these values explicitly doesn't cause an error.I would expect that neither are errors.
Code Snippet
Expected Behaviour
Both classes should pass type checking.
Actual Behaviour
Pyright flags an error on
SubDataclassProtocol
. Code works correctly.The text was updated successfully, but these errors were encountered: