Skip to content

Commit 3a5c8d7

Browse files
DinoVfacebook-github-bot
authored andcommitted
Don't optimize const binary subscr
Summary: Another optimization that has been removed from the AST optimizer. Reviewed By: mpage Differential Revision: D82128883 fbshipit-source-id: 3e94f95275ba722158142a557d3a794d63f51910
1 parent f76919e commit 3a5c8d7

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

cinderx/PythonLib/cinderx/compiler/optimizer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,12 @@ def visitBinOp(self, node: ast.BinOp) -> ast.expr:
509509

510510
return self.update_node(node, left=lhs, right=rhs)
511511

512+
def visitSubscript(self, node: ast.Subscript) -> ast.expr:
513+
value = self.visit(node.value)
514+
slice = self.visit(node.slice)
515+
516+
return self.update_node(node, value=value, slice=slice)
517+
512518
def visitMatchValue(self, node: ast.MatchValue) -> ast.MatchValue:
513519
return self.update_node(node, value=self.fold_const_match_patterns(node.value))
514520

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x = "string"[3]

0 commit comments

Comments
 (0)