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 unparsing of infinity numbers #77075

Closed
serhiy-storchaka opened this issue Feb 21, 2018 · 3 comments
Closed

AST unparsing of infinity numbers #77075

serhiy-storchaka opened this issue Feb 21, 2018 · 3 comments
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 32894
Nosy @gvanrossum, @mdickinson, @vstinner, @ambv, @serhiy-storchaka, @isidentical
PRs
  • bpo-32894: Support unparsing of infinity numbers in ast_unparser.c #17426
  • 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 = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2020-04-13.22:55:44.812>
    created_at = <Date 2018-02-21.12:20:59.154>
    labels = ['interpreter-core', '3.8', 'type-bug', '3.7', '3.9']
    title = 'AST unparsing of infinity numbers'
    updated_at = <Date 2020-04-13.22:55:44.811>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2020-04-13.22:55:44.811>
    actor = 'vstinner'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2020-04-13.22:55:44.812>
    closer = 'vstinner'
    components = ['Interpreter Core']
    creation = <Date 2018-02-21.12:20:59.154>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32894
    keywords = ['patch']
    message_count = 3.0
    messages = ['312492', '366343', '366347']
    nosy_count = 6.0
    nosy_names = ['gvanrossum', 'mark.dickinson', 'vstinner', 'lukasz.langa', 'serhiy.storchaka', 'BTaskaya']
    pr_nums = ['17426']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue32894'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @serhiy-storchaka
    Copy link
    Member Author

    AST unparsing of infinity numbers produces a string which can't be evaluated because inf and infj are not builtins.

    >>> from __future__ import annotations
    >>> def f(x: A[1e1000, 1e1000j]): pass
    ... 
    >>> f.__annotations__
    {'x': 'A[(inf, infj)]'}

    See how this problem is handled in Tools/parser/unparse.py.

    There is similar problem with NaN. NaN can't be a result of parsing Python sources, but it can be injected manually in AST, and it can be a result of third-party AST optimizer.

    @serhiy-storchaka serhiy-storchaka added 3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Feb 21, 2018
    @serhiy-storchaka serhiy-storchaka self-assigned this Nov 21, 2018
    @isidentical isidentical added the 3.9 only security fixes label Dec 1, 2019
    @vstinner
    Copy link
    Member

    New changeset 258f517 by Batuhan Taşkaya in branch 'master':
    bpo-32894: Support unparsing of infinity numbers in ast_unparser.c (GH-17426)
    258f517

    @vstinner
    Copy link
    Member

    It seems like the fix works as expected:

    >>> from __future__ import annotations
    >>> def f(x: A[1e1000, 1e1000j]): pass
    ... 
    
    >>> f.__annotations__
    {'x': 'A[1e309, 1e309j]'}
    
    >>> A=list
    >>> eval(f.__annotations__['x'])
    list[inf, infj]

    @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.7 (EOL) end of life 3.8 only security fixes 3.9 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

    3 participants