Skip to content

Commit 4691525

Browse files
committed
refactor: Remove deprecated ast.Index usage for Python 3.9+ compatibility
1 parent 1544091 commit 4691525

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/fluent_compiler/ast_compat.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def NewAst(...):
4040
ExceptHandler = ast.ExceptHandler
4141
Expr = ast.Expr
4242
If = ast.If
43-
Index = ast.Index
4443
List = ast.List
4544
Load = ast.Load
4645
Module = ast.Module
@@ -62,6 +61,15 @@ def NewAst(...):
6261
keyword = ast.keyword
6362
walk = ast.walk
6463

64+
# Index is deprecated in Python 3.9 and removed in 3.10+
65+
if sys.version_info < (3, 9):
66+
Index = ast.Index
67+
else:
68+
# In Python 3.9+, we don't need Index anymore as subscript slices
69+
# directly use the value
70+
def Index(value, **kwargs):
71+
return value
72+
6573

6674
if sys.version_info >= (3, 8):
6775
Constant = ast.Constant

src/fluent_compiler/codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ def __init__(self, lookup_obj, lookup_arg, expr_type=UNKNOWN_TYPE):
802802
def as_ast(self):
803803
return ast.Subscript(
804804
value=self.lookup_obj.as_ast(),
805-
slice=ast.Index(value=self.lookup_arg.as_ast(), **DEFAULT_AST_ARGS),
805+
slice=self.lookup_arg.as_ast(),
806806
ctx=ast.Load(),
807807
**DEFAULT_AST_ARGS,
808808
)

0 commit comments

Comments
 (0)