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 267d8a3c3dd21..f1b3d25301806 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_pie/PIE790.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_pie/PIE790.py @@ -227,3 +227,11 @@ def func(self) -> str: def impl(self) -> str: """Docstring""" return self.func() + + +import typing + +if typing.TYPE_CHECKING: + def contains_meaningful_ellipsis() -> list[int]: + """Allow this in a TYPE_CHECKING block.""" + ... 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 576cb21e35d35..09a58552d6357 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 @@ -87,6 +87,12 @@ pub(crate) fn unnecessary_placeholder(checker: &mut Checker, body: &[Stmt]) { let kind = match stmt { Stmt::Pass(_) => Placeholder::Pass, Stmt::Expr(expr) if expr.value.is_ellipsis_literal_expr() => { + // In a type-checking block, a trailing ellipsis might be meaningful. A + // user might be using the type-checking context to declare a stub. + if checker.semantic().in_type_checking_block() { + return; + } + // Ellipses are significant in protocol methods and abstract methods. Specifically, // Pyright uses the presence of an ellipsis to indicate that a method is a stub, // rather than a default implementation.