[issue39520] AST Unparser can't unparse ext slices correctly

Batuhan report at bugs.python.org
Sat Feb 1 16:10:07 EST 2020


New submission from Batuhan <batuhanosmantaskaya at gmail.com>:

(this issue has already a PR for ast.unparse)

>>> from __future__ import annotations
>>> import ast
>>> x: Tuple[1:2,] = 3
>>> __annotations__["x"]
'Tuple[1:2]'
>>> ast.dump(ast.parse("Tuple[1:2,]"))
"Module(body=[Expr(value=Subscript(value=Name(id='Tuple', ctx=Load()), slice=ExtSlice(dims=[Slice(lower=Constant(value=1, kind=None), upper=Constant(value=2, kind=None), step=None)]), ctx=Load()))], type_ignores=[])"

>>> ast.dump(ast.parse("Tuple[1:2]"))
"Module(body=[Expr(value=Subscript(value=Name(id='Tuple', ctx=Load()), slice=Slice(lower=Constant(value=1, kind=None), upper=Constant(value=2, kind=None), step=None), ctx=Load()))], type_ignores=[])"

----------
components: Interpreter Core
messages: 361193
nosy: BTaskaya
priority: normal
severity: normal
status: open
title: AST Unparser can't unparse ext slices correctly
type: behavior
versions: Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39520>
_______________________________________


More information about the Python-bugs-list mailing list