Skip to content

Commit fe46b03

Browse files
committed
fix
1 parent 425f24e commit fe46b03

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Lib/ast.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"""
2323
from _ast import *
2424

25+
type_None = type(None)
26+
type_Ellipsis = type(...)
2527

2628
def parse(source, filename='<unknown>', mode='exec', *,
2729
type_comments=False, feature_version=None, optimize=-1, module=None):
@@ -68,8 +70,12 @@ def _convert_literal(node):
6870
"""
6971
Used by `literal_eval` to convert an AST node into a value.
7072
"""
71-
if isinstance(node, Constant):
72-
return node.value
73+
if (
74+
isinstance(node, Constant)
75+
and type(value := node.value) in (int, float, complex, bytes, bool,
76+
type_None, type_Ellipsis)
77+
):
78+
return value
7379
if isinstance(node, Dict) and len(node.keys) == len(node.values):
7480
return dict(zip(
7581
map(_convert_literal, node.keys),

0 commit comments

Comments
 (0)