Author serhiy.storchaka
Recipients benjamin.peterson, brett.cannon, gvanrossum, ncoghlan, serhiy.storchaka, vstinner, yselivanov
Date 2018-02-21.09:16:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Currently different literals are represented by different types in AST:

Num -- for int, float and complex
Str -- for str
Bytes -- for bytes
Ellipsis -- for Ellipsis
NameConstant -- for True, False and None

And Constant (added in 3.6, issue26146) can represent any immutable value, including tuples and frozensets of constants. Instances of Constant are not created by the AST parser, they are created by the builtin AST optimizer and can be created manually.

These AST types don't have one-to-one correspondence with Python types, since Num represents three numeric types, NameConstant represents bool and NoneType, and any constant type can be represented as Constant.

I propose to get rid of Num, Str, Bytes, Ellipsis and NameConstant and always use Constant. This will simplify the code which currently needs to repeat virtually identical code for all types.

I have almost ready patch, the only question is whether it is worth to keep deprecated aliases Num, Str, Bytes, Ellipsis and NameConstant.
Date User Action Args
2018-02-21 09:16:37serhiy.storchakasetrecipients: + serhiy.storchaka, gvanrossum, brett.cannon, ncoghlan, vstinner, benjamin.peterson, yselivanov
2018-02-21 09:16:37serhiy.storchakasetmessageid: <>
2018-02-21 09:16:37serhiy.storchakalinkissue32892 messages
2018-02-21 09:16:36serhiy.storchakacreate