Skip to content

Commit f2a6c09

Browse files
committed
CLN: Loop with idx check location_tup len fields
1 parent e4c8f2b commit f2a6c09

1 file changed

Lines changed: 17 additions & 18 deletions

File tree

‎vm/src/exceptions.rs‎

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,24 +1619,23 @@ pub(super) mod types {
16191619
.clone()
16201620
.downcast::<crate::builtins::PyTuple>()
16211621
{
1622-
#[allow(clippy::len_zero)]
1623-
if location_tuple.len() >= 1 {
1624-
zelf.set_attr("filename", location_tuple.fast_getitem(0).clone(), vm)?;
1625-
}
1626-
if location_tuple.len() >= 2 {
1627-
zelf.set_attr("lineno", location_tuple.fast_getitem(1).clone(), vm)?;
1628-
}
1629-
if location_tuple.len() >= 3 {
1630-
zelf.set_attr("offset", location_tuple.fast_getitem(2).clone(), vm)?;
1631-
}
1632-
if location_tuple.len() >= 4 {
1633-
zelf.set_attr("text", location_tuple.fast_getitem(3).clone(), vm)?;
1634-
}
1635-
if location_tuple.len() >= 5 {
1636-
zelf.set_attr("end_lineno", location_tuple.fast_getitem(4).clone(), vm)?;
1637-
}
1638-
if location_tuple.len() >= 6 {
1639-
zelf.set_attr("end_offset", location_tuple.fast_getitem(5).clone(), vm)?;
1622+
let location_tup_len = location_tuple.len();
1623+
for (i, &attr) in [
1624+
"filename",
1625+
"lineno",
1626+
"offset",
1627+
"text",
1628+
"end_lineno",
1629+
"end_offset",
1630+
]
1631+
.iter()
1632+
.enumerate()
1633+
{
1634+
if location_tup_len > i {
1635+
zelf.set_attr(attr, location_tuple.fast_getitem(i).clone(), vm)?;
1636+
} else {
1637+
break;
1638+
}
16401639
}
16411640
}
16421641
}

0 commit comments

Comments
 (0)