Skip to content

Commit 9675e18

Browse files
authored
Allow trailing ellipsis in typing.TYPE_CHECKING (#10413)
## Summary Trailing ellipses in objects defined in `typing.TYPE_CHECKING` might be meaningful (it might be declaring a stub). Thus, we should skip the `unnecessary-placeholder` (`PIE970`) rule in such contexts. Closes #10358. ## Test Plan `cargo nextest run`
1 parent 10ace88 commit 9675e18

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

crates/ruff_linter/resources/test/fixtures/flake8_pie/PIE790.py

+8
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,11 @@ def func(self) -> str:
227227
def impl(self) -> str:
228228
"""Docstring"""
229229
return self.func()
230+
231+
232+
import typing
233+
234+
if typing.TYPE_CHECKING:
235+
def contains_meaningful_ellipsis() -> list[int]:
236+
"""Allow this in a TYPE_CHECKING block."""
237+
...

crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_placeholder.rs

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ pub(crate) fn unnecessary_placeholder(checker: &mut Checker, body: &[Stmt]) {
8787
let kind = match stmt {
8888
Stmt::Pass(_) => Placeholder::Pass,
8989
Stmt::Expr(expr) if expr.value.is_ellipsis_literal_expr() => {
90+
// In a type-checking block, a trailing ellipsis might be meaningful. A
91+
// user might be using the type-checking context to declare a stub.
92+
if checker.semantic().in_type_checking_block() {
93+
return;
94+
}
95+
9096
// Ellipses are significant in protocol methods and abstract methods. Specifically,
9197
// Pyright uses the presence of an ellipsis to indicate that a method is a stub,
9298
// rather than a default implementation.

0 commit comments

Comments
 (0)