Skip to content

Commit c812256

Browse files
Avoid triggering NamedTuple rewrite with starred annotation (#8434)
See: #8402 (comment)
1 parent f8f507c commit c812256

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

crates/ruff_linter/resources/test/fixtures/pyupgrade/UP014.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@
2323
MyType = typing.NamedTuple("MyType", [("a", int)], [("b", str)])
2424
MyType = typing.NamedTuple("MyType", [("a", int)], b=str)
2525
MyType = typing.NamedTuple(typename="MyType", a=int, b=str)
26+
27+
# Regression test for: https://github.com/astral-sh/ruff/issues/8402#issuecomment-1788787357
28+
S3File = NamedTuple(
29+
"S3File",
30+
[
31+
("dataHPK",* str),
32+
],
33+
)

crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ fn create_fields_from_fields_arg(fields: &Expr) -> Option<Vec<Stmt>> {
181181
let [field, annotation] = elts.as_slice() else {
182182
return None;
183183
};
184+
if annotation.is_starred_expr() {
185+
return None;
186+
}
184187
let ast::ExprStringLiteral { value: field, .. } = field.as_string_literal_expr()?;
185188
if !is_identifier(field) {
186189
return None;

0 commit comments

Comments
 (0)