Skip to content

Commit 53e9620

Browse files
committed
simplify check for permitted types
1 parent e3c4a80 commit 53e9620

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

Lib/ast.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def literal_eval(node_or_string):
6565
return _convert_literal(node_or_string)
6666

6767

68-
_type_None = type(None)
69-
_type_Ellipsis = type(...)
68+
_permitted_literal_types = (str, bytes, int, float, complex,
69+
bool, type(None), type(...))
7070

7171

7272
def _convert_literal(node, omit_validation=False):
@@ -76,8 +76,7 @@ def _convert_literal(node, omit_validation=False):
7676
if isinstance(node, Constant):
7777
if omit_validation:
7878
return node.value
79-
if type(value := node.value) in (str, bytes, int, float, complex,
80-
bool, _type_None, _type_Ellipsis):
79+
if type(value := node.value) in _permitted_literal_types:
8180
return value
8281
if isinstance(node, Dict) and len(node.keys) == len(node.values):
8382
return dict(zip(

0 commit comments

Comments
 (0)