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.

Title: AST unparsing of infinity numbers
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.9, Python 3.8, Python 3.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: BTaskaya, gvanrossum, lukasz.langa, mark.dickinson, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2018-02-21 12:20 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 17426 merged BTaskaya, 2019-12-01 18:38
Messages (3)
msg312492 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-02-21 12:20
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/

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.
msg366343 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-04-13 22:51
New changeset 258f5179f9494189e6a80311c86981d2a88ba9d6 by Batuhan Taşkaya in branch 'master':
bpo-32894: Support unparsing of infinity numbers in ast_unparser.c (GH-17426)
msg366347 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-04-13 22:55
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]
Date User Action Args
2022-04-11 14:58:58adminsetgithub: 77075
2020-04-13 22:55:44vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg366347

stage: patch review -> resolved
2020-04-13 22:51:37vstinnersetnosy: + vstinner
messages: + msg366343
2019-12-01 18:38:27BTaskayasetkeywords: + patch
stage: patch review
pull_requests: + pull_request16905
2019-12-01 18:35:53BTaskayasetnosy: + BTaskaya
2019-12-01 18:35:44BTaskayasetversions: + Python 3.9
2018-11-21 14:23:10mark.dickinsonsetnosy: + mark.dickinson
2018-11-21 08:33:49serhiy.storchakasetassignee: serhiy.storchaka
2018-02-21 12:20:59serhiy.storchakacreate