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 serhiy.storchaka
Recipients benjamin.peterson, rhettinger, serhiy.storchaka, terry.reedy
Date 2018-02-24.06:55:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The definition of "Python literal structures" is not specified, but it is implied that ast.literal_eval() should accept signed numbers and tuple/list/set/dict displays consisting of "Python literal structures".

ast.literal_eval() accepts unary minus for supporting negative numbers. In Python 2 "-42" was parsed as a single AST node Num(42), but in Python 3 it is parsed as UnaryOp(USub(), Num(42)). ast.literal_eval() accepts binary plus and minus for supporting complex numbers (there are oddities in this). The support of unary plus was added somewhere for unknown reason (see 884c71cd8dc6, no issue number), but it doesn't harm.

Below in the documentation: "It is not capable of evaluating arbitrarily complex expressions, for example involving operators or indexing." Arbitrarily complex expressions involving addition and subtraction (like "2017-10-10") was supported in Python 3 (but not in Python 2), but it was fixed in 3.7 (see issue31778). It doesn't support other operations or operations with non-numeric literals. It is oversight that UnaryOp(USub(), Constant(True)) is still accepted.
Date User Action Args
2018-02-24 06:55:07serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, terry.reedy, benjamin.peterson
2018-02-24 06:55:07serhiy.storchakasetmessageid: <>
2018-02-24 06:55:07serhiy.storchakalinkissue32893 messages
2018-02-24 06:55:06serhiy.storchakacreate