mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-02 04:48:06 +00:00
Respect generic Protocol in ellipsis removal (#9841)
Closes https://github.com/astral-sh/ruff/issues/9840.
This commit is contained in:
parent
36b752876e
commit
041ce1e166
3 changed files with 25 additions and 1 deletions
|
|
@ -207,3 +207,23 @@ class Repro:
|
|||
def stub(self) -> str:
|
||||
"""Docstring"""
|
||||
...
|
||||
|
||||
|
||||
class Repro(Protocol[int]):
|
||||
def func(self) -> str:
|
||||
"""Docstring"""
|
||||
...
|
||||
|
||||
def impl(self) -> str:
|
||||
"""Docstring"""
|
||||
return self.func()
|
||||
|
||||
|
||||
class Repro[int](Protocol):
|
||||
def func(self) -> str:
|
||||
"""Docstring"""
|
||||
...
|
||||
|
||||
def impl(self) -> str:
|
||||
"""Docstring"""
|
||||
return self.func()
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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]):
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue