bpo-43521: Allow ast.unparse with empty sets and NaN by Kodiologist · Pull Request #24897 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 14 additions & 6 deletions Lib/ast.py
15 changes: 12 additions & 3 deletions Lib/test/test_unparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ def test_huge_float(self):
self.check_ast_roundtrip("1e1000j")
self.check_ast_roundtrip("-1e1000j")

def test_nan(self):
self.assertASTEqual(
ast.parse(ast.unparse(ast.Constant(value=float('nan')))),
ast.parse('1e1000 - 1e1000')
)

def test_min_int(self):
self.check_ast_roundtrip(str(-(2 ** 31)))
self.check_ast_roundtrip(str(-(2 ** 63)))
Expand Down Expand Up @@ -252,6 +258,12 @@ def test_annotations(self):
def test_set_literal(self):
self.check_ast_roundtrip("{'a', 'b', 'c'}")

def test_empty_set(self):
self.assertASTEqual(
ast.parse(ast.unparse(ast.Set(elts=[]))),
ast.parse('{*()}')
)

def test_set_comprehension(self):
self.check_ast_roundtrip("{x for x in range(5)}")

Expand Down Expand Up @@ -326,9 +338,6 @@ def test_invalid_fstring_conversion(self):
def test_invalid_fstring_backslash(self):
self.check_invalid(ast.FormattedValue(value=ast.Constant(value="\\\\")))

def test_invalid_set(self):
self.check_invalid(ast.Set(elts=[]))

def test_invalid_yield_from(self):
self.check_invalid(ast.YieldFrom(value=None))

Expand Down