Skip to content

Commit

Permalink
fix: slice bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Dec 27, 2024
1 parent deb6736 commit 0da66dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crates/py2erg/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,7 @@ impl ASTConverter {
);
method.call1(self.convert_expr(*subs.slice))
}
// [:] == [slice(None)]
// [start:] == [slice(start, None)]
// [:stop] == [slice(stop)]
// [start:stop] == [slice(start, stop)]
Expand All @@ -1905,6 +1906,14 @@ impl ASTConverter {
if let Some(step) = step {
args.push_pos(PosArg::new(step));
}
if args.is_empty() {
args.push_pos(PosArg::new(Expr::Literal(Literal::new(Token::new(
TokenKind::NoneLit,
"None",
loc.row.get(),
loc.column.to_zero_indexed(),
)))));
}
let slice = self.convert_ident("slice".to_string(), loc);
slice.call(args).into()
}
Expand Down
4 changes: 4 additions & 0 deletions tests/list.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
l = [1, 2, 3]
_ = l[1:2]
_ = l[:]
_ = l[1:]
_ = l[:1]
_ = l[1:1:1]
print(l[2])
print(l["a"]) # ERR

Expand Down

0 comments on commit 0da66dc

Please sign in to comment.