Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion crates/ruff_linter/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,15 @@ impl<'a> Visitor<'a> for Checker<'a> {
}
self.visit_expr_context(ctx);
} else {
debug!("Found non-Expr::Tuple argument to PEP 593 Annotation.");
if self.semantic.in_type_definition() {
// this should potentially trigger some kind of violation in the
// future, since it would indicate an invalid type expression
debug!("Found non-Expr::Tuple argument to PEP 593 Annotation.");
}
// even if the expression is invalid as a type expression, we should
// still visit it so we don't accidentally treat variables as unused
self.visit_expr(slice);
self.visit_expr_context(ctx);
}
}
Some(typing::SubscriptKind::TypedDict) => {
Expand Down
18 changes: 18 additions & 0 deletions crates/ruff_linter/src/rules/pyflakes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4263,4 +4263,22 @@ lambda: fu
&[],
);
}

#[test]
fn gh_issue_17196_regression_test() {
flakes(
r#"
from typing import Annotated

def type_annotations_from_tuple():
annos = (str, "foo", "bar")
return Annotated[annos]

def type_annotations_from_filtered_tuple():
annos = (str, None, "foo", None, "bar")
return Annotated[tuple([a for a in annos if a is not None])]
"#,
&[],
);
}
}
Loading