mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:25:17 +00:00
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`
This commit is contained in:
parent
10ace88e9a
commit
9675e1867a
2 changed files with 14 additions and 0 deletions
|
@ -227,3 +227,11 @@ class Repro[int](Protocol):
|
|||
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."""
|
||||
...
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue