utils: fix subscript checking for python 3.9 (#49608)
This commit is contained in:
parent
ae5a9c0b3d
commit
081a4e5798
|
@ -183,10 +183,18 @@ class ConditionValidator(BaseExpressionValidator):
|
|||
|
||||
def check_Subscript(self, node):
|
||||
# check subscript are constant number or strings
|
||||
if (not isinstance(node.slice, ast.Index)
|
||||
or not isinstance(node.slice.value, CONSTANT_CLASSES)
|
||||
# with python <3.8 the node class is enough to determine the value
|
||||
or (sys.version_info >= (3, 8) and not isinstance(node.slice.value.value, (int, str, bytes)))):
|
||||
ok = True
|
||||
if sys.version_info >= (3, 9):
|
||||
ok = isinstance(node.slice, CONSTANT_CLASSES)
|
||||
elif sys.version_info >= (3, 8):
|
||||
ok = (
|
||||
isinstance(node.slice, ast.Index)
|
||||
and isinstance(node.slice.value, CONSTANT_CLASSES)
|
||||
and isinstance(node.slice.value.value, (int, str, bytes))
|
||||
)
|
||||
else:
|
||||
ok = isinstance(node.slice, ast.Index) and isinstance(node.slice.value, CONSTANT_CLASSES)
|
||||
if not ok:
|
||||
raise ExpressionError(_('subscript index MUST be a constant'), code='invalid-subscript', node=node)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue