Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AST: FomattedValue conversion's default value should be -1 #90447

Closed
iyume mannequin opened this issue Jan 7, 2022 · 8 comments
Closed

AST: FomattedValue conversion's default value should be -1 #90447

iyume mannequin opened this issue Jan 7, 2022 · 8 comments
Labels
3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@iyume
Copy link
Mannequin

iyume mannequin commented Jan 7, 2022

BPO 46289
Nosy @lysnikolaou, @pablogsal, @miss-islington, @isidentical, @iyume
PRs
  • bpo-46289: Make conversion of FormattedValue not optional on ASDL #30467
  • [3.10] bpo-46289: Make conversion of FormattedValue not optional on ASDL (GH-30467) #30469
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2022-01-07.22:53:32.580>
    created_at = <Date 2022-01-07.09:40:18.888>
    labels = ['interpreter-core', 'type-bug', '3.10', '3.11']
    title = "AST: FomattedValue conversion's default value should be -1"
    updated_at = <Date 2022-01-07.22:53:32.579>
    user = 'https://github.com/iyume'

    bugs.python.org fields:

    activity = <Date 2022-01-07.22:53:32.579>
    actor = 'BTaskaya'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-01-07.22:53:32.580>
    closer = 'BTaskaya'
    components = ['Parser']
    creation = <Date 2022-01-07.09:40:18.888>
    creator = 'iyume'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46289
    keywords = ['patch']
    message_count = 8.0
    messages = ['409955', '409982', '409985', '409986', '410034', '410042', '410044', '410049']
    nosy_count = 6.0
    nosy_names = ['lys.nikolaou', 'pablogsal', 'miss-islington', 'BTaskaya', 'Batuhan Taskaya', 'iyume']
    pr_nums = ['30467', '30469']
    priority = 'normal'
    resolution = None
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46289'
    versions = ['Python 3.10', 'Python 3.11']

    @iyume
    Copy link
    Mannequin Author

    iyume mannequin commented Jan 7, 2022

    An unexpected behavior lookup:

    >>> ast.FormattedValue(ast.Str('ss')).conversion
    >>> ast.unparse(ast.FormattedValue(ast.Str('ss')))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python3.9/ast.py", line 1564, in unparse
        return unparser.visit(ast_obj)
      File "/usr/local/lib/python3.9/ast.py", line 801, in visit
        self.traverse(node)
      File "/usr/local/lib/python3.9/ast.py", line 795, in traverse
        super().visit(node)
      File "/usr/local/lib/python3.9/ast.py", line 407, in visit
        return visitor(node)
      File "/usr/local/lib/python3.9/ast.py", line 1153, in visit_FormattedValue
        self._fstring_FormattedValue(node, self.buffer_writer)
      File "/usr/local/lib/python3.9/ast.py", line 1178, in _fstring_FormattedValue
        conversion = chr(node.conversion)
    TypeError: an integer is required (got type NoneType)
    >>> ast.unparse(ast.FormattedValue(ast.Str('ss'), -1))
    'f"{\'ss\'}"'

    ast.FormattedValue conversion's default value is expected to be -1 but not None

    See: https://docs.python.org/3/library/ast.html#ast.FormattedValue

    Other:

    If certainly, it's also a bug on typeshed.

    @iyume iyume mannequin added 3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jan 7, 2022
    @isidentical
    Copy link
    Sponsor Member

    ASDL technically allows it to be None though neither compiler nor ast.unparse can work with it at this moment.

    FormattedValue(expr value, int? conversion, expr? format_spec)

    | FormattedValue(expr value, int? conversion, expr? format_spec)

    >>> import ast
    >>> tree = ast.parse("f'{x + 1}'")
    >>> tree.body[0].value.values[0].conversion = None
    >>> compile(tree, "<test>", "exec")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    SystemError: Unrecognized conversion character 0

    We can either:
    A) change ASDL to reflect it is an integer (since it always has been treated that way)
    B) Support this on both the compiler as well as in the ast.unparse

    I'd say A, since this was always broken. @pablogsal @lys.nikolaou WDYT?

    @lysnikolaou
    Copy link
    Contributor

    I agree that A is probably the way to go.

    @pablogsal
    Copy link
    Member

    I think A is the best option

    @miss-islington
    Copy link
    Contributor

    New changeset d382f7e by Batuhan Taskaya in branch 'main':
    bpo-46289: Make conversion of FormattedValue not optional on ASDL (GH-30467)
    d382f7e

    @BatuhanTaskaya
    Copy link
    Mannequin

    BatuhanTaskaya mannequin commented Jan 7, 2022

    Should we backport this?

    On Sat, Jan 8, 2022, 12:05 AM miss-islington <report@bugs.python.org> wrote:

    miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the
    comment:

    New changeset d382f7e by Batuhan Taskaya
    in branch 'main':
    bpo-46289: Make conversion of FormattedValue not optional on ASDL
    (GH-30467)

    d382f7e

    ----------
    nosy: +miss-islington


    Python tracker <report@bugs.python.org>
    <https://bugs.python.org/issue46289\>


    @pablogsal
    Copy link
    Member

    I would say yes, for consistency. It doesn't have any effects on user code that I am aware

    @miss-islington
    Copy link
    Contributor

    New changeset bea3f42 by Miss Islington (bot) in branch '3.10':
    bpo-46289: Make conversion of FormattedValue not optional on ASDL (GH-30467)
    bea3f42

    @isidentical isidentical added 3.10 only security fixes 3.11 only security fixes and removed 3.9 only security fixes labels Jan 7, 2022
    @isidentical isidentical added 3.10 only security fixes 3.11 only security fixes and removed 3.9 only security fixes labels Jan 7, 2022
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants