Skip to content

Commit

Permalink
Respect generic Protocol in ellipsis removal
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 5, 2024
1 parent e708c08 commit bd03567
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/flake8_pie/PIE790.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,13 @@ def impl(self) -> str:
def stub(self) -> str:
"""Docstring"""
...


class Repro(Protocol[int]):
def func(self) -> str:
"""Docstring"""
...

def impl(self) -> str:
"""Docstring"""
return self.func()
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use ruff_diagnostics::AlwaysFixableViolation;
use ruff_diagnostics::{Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::map_subscript;
use ruff_python_ast::whitespace::trailing_comment_start_offset;
use ruff_python_ast::Stmt;
use ruff_python_semantic::{ScopeKind, SemanticModel};
Expand Down Expand Up @@ -132,7 +133,7 @@ fn in_protocol_or_abstract_method(semantic: &SemanticModel) -> bool {
ScopeKind::Class(class_def) => class_def
.bases()
.iter()
.any(|base| semantic.match_typing_expr(base, "Protocol")),
.any(|base| semantic.match_typing_expr(map_subscript(base), "Protocol")),
ScopeKind::Function(function_def) => {
ruff_python_semantic::analyze::visibility::is_abstract(
&function_def.decorator_list,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,5 +671,8 @@ PIE790.py:209:9: PIE790 [*] Unnecessary `...` literal
207 207 | def stub(self) -> str:
208 208 | """Docstring"""
209 |- ...
210 209 |
211 210 |
212 211 | class Repro(Protocol[int]):


0 comments on commit bd03567

Please sign in to comment.