-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Bug in PIE790 in Ruff v0.1.6 (...
is meaningful in protocol methods and should not be removed)
#8756
Comments
Thanks for the report! Would you mind reporting this on mypy? This seems like a bug on their end unless there's something in the specification that says |
Ah, I didn't think of it this way! Yeah, it's possible Pyright is in the (heh) wrong here. I'll report! |
I'm the author of pyright, and I can say that this isn't a bug in pyright. Ruff's formatter should not remove the ellipsis in this case because it has significant meaning. A protocol class is allowed to provide a default implementation for a method, in which case all subclasses of that protocol inherit that implementation. If the implementation of a method does not include a I'll note that |
...
is necessary for protocol methods which return something else than None)...
is meaningul in protocol methods and should not be removed)
...
is meaningul in protocol methods and should not be removed)...
is meaningful in protocol methods and should not be removed)
Thanks for the context Eric! This isn't part of Ruff's formatter — it will never change the semantics of the code. This is a fix for rule removing unnecessary Regardless, I think we should add a special exemption to this lint rule in Ruff. |
It looks like mypy (1.7.0) does not raise an error for this from typing import Protocol
class Repro(Protocol):
def foo(self) -> str:
"""docblock""" |
The protocol spec doesn't specify this, nor do any other parts of the typing spec. Pyright's treatment of Mypy's treatment of
Ah, I see. Thanks for the clarification. Yes, I agree that it would be good to add an exemption for this case. The |
Thanks @erictraut! Does this apply anywhere outside of |
It also applies to abstract methods (those decorated with
Great to hear! |
Okay great, thanks Eric! |
I can take this one since it's my regression :) |
## Summary It turns out that some type checkers rely on the presence of ellipses in `Protocol` interfaces and abstract methods, in order to differentiate between default implementations and stubs. This PR modifies the preview behavior of `PIE790` to avoid flagging "unnecessary" ellipses in such cases. Closes #8756. ## Test Plan `cargo test`
This seems somehow caused by astral-sh/ruff#8756, which is marked closed. Here comes a rabbit hole to find out why this cropped up now.
This also applies for stubs defined inside |
Hey, I've got a regression in Ruff 0.1.6 to report.
PIE790 wants the
...
removed, but it's necessary in this case – becausefoo
is a protocol method:At least according to Pyright 1.1.336, which shows this error if I allow Ruff to remove the
...
:The text was updated successfully, but these errors were encountered: