This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Ilya Kamenshchikov
Recipients Ilya Kamenshchikov
Date 2020-02-26.12:43:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1582720982.96.0.367799860574.issue39760@roundup.psfhosted.org>
In-reply-to
Content
Most usual usecase for format_spec is to specify it as a constant, that would be logical to represent as ast.Constant. However, ast.parse wraps value of ast.FormattedValue.format_spec into a JoinedStr with a single constant value, as can be seen from example below:


import ast

code = '''f"is {x:d}"'''
tree = ast.parse(code)

for n in ast.walk(tree):
    if isinstance(n, ast.FormattedValue):
        print(
            type(n.format_spec),
            len(n.format_spec.values),
            set(type(v) for v in n.format_spec.values),
        )

This is confusing for programmatically analyzing the ast, and likely creates some overhead in any modules using ast and FormattedValue.

Proposal: represent ast.FormattedValue.format_spec as ast.Constant in most cases.
History
Date User Action Args
2020-02-26 12:43:03Ilya Kamenshchikovsetrecipients: + Ilya Kamenshchikov
2020-02-26 12:43:02Ilya Kamenshchikovsetmessageid: <1582720982.96.0.367799860574.issue39760@roundup.psfhosted.org>
2020-02-26 12:43:02Ilya Kamenshchikovlinkissue39760 messages
2020-02-26 12:43:02Ilya Kamenshchikovcreate