diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_pie/PIE790.py b/crates/ruff_linter/resources/test/fixtures/flake8_pie/PIE790.py index 654b7e5aba8c2..267d8a3c3dd21 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_pie/PIE790.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_pie/PIE790.py @@ -207,3 +207,23 @@ 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() + + +class Repro[int](Protocol): + def func(self) -> str: + """Docstring""" + ... + + def impl(self) -> str: + """Docstring""" + return self.func() diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_placeholder.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_placeholder.rs index c3997a534fdf1..576cb21e35d35 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_placeholder.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_placeholder.rs @@ -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, diff --git a/crates/ruff_linter/src/rules/flake8_pie/snapshots/ruff_linter__rules__flake8_pie__tests__PIE790_PIE790.py.snap b/crates/ruff_linter/src/rules/flake8_pie/snapshots/ruff_linter__rules__flake8_pie__tests__PIE790_PIE790.py.snap index e881a177deee5..b2356b7f347a8 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/snapshots/ruff_linter__rules__flake8_pie__tests__PIE790_PIE790.py.snap +++ b/crates/ruff_linter/src/rules/flake8_pie/snapshots/ruff_linter__rules__flake8_pie__tests__PIE790_PIE790.py.snap @@ -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]):