From deaaccff7c02a9e1e3e1b2c9ee56954be2fb5673 Mon Sep 17 00:00:00 2001 From: th3-j4ck4l Date: Mon, 6 Apr 2020 19:37:59 +0300 Subject: [PATCH] Resolves #8627 --- mypy/fastparse.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mypy/fastparse.py b/mypy/fastparse.py index e72d2687351a0..2989829dba091 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -1504,17 +1504,22 @@ def visit_Bytes(self, n: Bytes) -> Type: # Subscript(expr value, slice slice, expr_context ctx) def visit_Subscript(self, n: ast3.Subscript) -> Type: - if not isinstance(n.slice, Index): - self.fail(TYPE_COMMENT_SYNTAX_ERROR, self.line, getattr(n, 'col_offset', -1)) - return AnyType(TypeOfAny.from_error) + + if PY_MINOR_VERSION >= 9: + slice_value = n.slice + else: + if not isinstance(n.slice, Index): + self.fail(TYPE_COMMENT_SYNTAX_ERROR, self.line, getattr(n, 'col_offset', -1)) + return AnyType(TypeOfAny.from_error) + slice_value = n.slice.value empty_tuple_index = False - if isinstance(n.slice.value, ast3.Tuple): - params = self.translate_expr_list(n.slice.value.elts) - if len(n.slice.value.elts) == 0: + if isinstance(slice_value, ast3.Tuple): + params = self.translate_expr_list(slice_value.elts) + if len(slice_value.elts) == 0: empty_tuple_index = True else: - params = [self.visit(n.slice.value)] + params = [self.visit(slice_value)] value = self.visit(n.value) if isinstance(value, UnboundType) and not value.args: