Projet

Général

Profil

0001-utils-fix-subscript-checking-for-python-3.9-49608.patch

Benjamin Dauvergne, 18 décembre 2020 14:51

Télécharger (1,64 ko)

Voir les différences:

Subject: [PATCH] utils: fix subscript checking for python 3.9 (#49608)

 src/authentic2/utils/evaluate.py | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
src/authentic2/utils/evaluate.py
183 183

  
184 184
    def check_Subscript(self, node):
185 185
        # check subscript are constant number or strings
186
        if (not isinstance(node.slice, ast.Index)
187
                or not isinstance(node.slice.value, CONSTANT_CLASSES)
188
                # with python <3.8 the node class is enough to determine the value
189
                or (sys.version_info >= (3, 8) and not isinstance(node.slice.value.value, (int, str, bytes)))):
186
        ok = True
187
        if sys.version_info >= (3, 9):
188
            ok = isinstance(node.slice, CONSTANT_CLASSES)
189
        elif sys.version_info >= (3, 8):
190
            ok = (
191
                isinstance(node.slice, ast.Index)
192
                and isinstance(node.slice.value, CONSTANT_CLASSES)
193
                and isinstance(node.slice.value.value, (int, str, bytes))
194
            )
195
        else:
196
            ok = isinstance(node.slice, ast.Index) and isinstance(node.slice.value, CONSTANT_CLASSES)
197
        if not ok:
190 198
            raise ExpressionError(_('subscript index MUST be a constant'), code='invalid-subscript', node=node)
191 199

  
192 200

  
193
-