Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"""
from _ast import *

type_None = type(None)
type_Ellipsis = type(...)

def parse(source, filename='<unknown>', mode='exec', *,
type_comments=False, feature_version=None, optimize=-1, module=None):
Expand Down Expand Up @@ -68,8 +70,12 @@ def _convert_literal(node):
"""
Used by `literal_eval` to convert an AST node into a value.
"""
if isinstance(node, Constant):
return node.value
if (
isinstance(node, Constant)
and type(value := node.value) in (int, float, complex, bytes, bool,
Comment thread
XChaitanyaX marked this conversation as resolved.
Outdated
type_None, type_Ellipsis)
):
return value
if isinstance(node, Dict) and len(node.keys) == len(node.values):
return dict(zip(
map(_convert_literal, node.keys),
Expand Down
Loading