Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow trailing ellipsis in typing.TYPE_CHECKING #10413

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
...
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ pub(crate) fn unnecessary_placeholder(checker: &mut Checker, body: &[Stmt]) {
return;
}

// 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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be down at the in_protocol_or_abstract_method line? (I.e., shouldn't this only apply to ellipses, not stubs?)


for stmt in body {
let kind = match stmt {
Stmt::Pass(_) => Placeholder::Pass,
Expand Down