[New-bugs-announce] [issue32893] ast.literal_eval() shouldn't accept booleans as numbers in AST

Serhiy Storchaka report at bugs.python.org
Wed Feb 21 04:56:21 EST 2018


New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:

Currently ast.literal_eval() accepts AST representing expressions like "+True" or "True+2j" if constants are represented as Constant. This is because the type of the value is tested with `isinstance(left, (int, float))` and since bool is a subclass of int it passes this test.

The proposed PR makes ast.literal_eval() using tests for exact type. I don't think it is worth backporting since it affects only passing AST to ast.literal_eval(). Usually ast.literal_eval() is used for evaluating strings.

----------
components: Library (Lib)
messages: 312485
nosy: serhiy.storchaka
priority: normal
severity: normal
status: open
title: ast.literal_eval() shouldn't accept booleans as numbers in AST
type: enhancement
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32893>
_______________________________________


More information about the New-bugs-announce mailing list