Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit abe52d7

Browse files
committed
Revert accidental extra changes included in r82391.
1 parent 50b79a8 commit abe52d7

2 files changed

Lines changed: 5 additions & 42 deletions

File tree

Demo/parser/test_unparse.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ def test_while_else(self):
123123

124124
def test_unary_parens(self):
125125
self.check_roundtrip("(-1)**7")
126-
self.check_roundtrip("(-1.)**8")
127-
self.check_roundtrip("(-1j)**6")
128126
self.check_roundtrip("not True or False")
129127
self.check_roundtrip("True or not False")
130128

@@ -134,16 +132,6 @@ def test_integer_parens(self):
134132
def test_huge_float(self):
135133
self.check_roundtrip("1e1000")
136134
self.check_roundtrip("-1e1000")
137-
self.check_roundtrip("1e1000j")
138-
self.check_roundtrip("-1e1000j")
139-
140-
def test_min_int(self):
141-
self.check_roundtrip(str(-2**31))
142-
self.check_roundtrip(str(-2**63))
143-
144-
def test_imag_literals(self):
145-
self.check_roundtrip("7j")
146-
self.check_roundtrip("-7j")
147135

148136
def test_lambda_parentheses(self):
149137
self.check_roundtrip("(lambda: int)()")
@@ -213,7 +201,7 @@ class DirectoryTestCase(ASTTestCase):
213201
# test directories, relative to the root of the distribution
214202
test_directories = 'Lib', os.path.join('Lib', 'test')
215203

216-
def Xtest_files(self):
204+
def test_files(self):
217205
# get names of files to test
218206
dist_dir = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)
219207

Demo/parser/unparse.py

100755100644
Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#! /usr/bin/env python3.1
21
"Usage: unparse.py <path to source file>"
32
import sys
43
import math
@@ -312,35 +311,11 @@ def _Name(self, t):
312311
self.write(t.id)
313312

314313
def _Num(self, t):
315-
# Python doesn't have negative numeric literals, but in Python
316-
# 2.x and early versions of Python 3.1, there's a compile-time
317-
# operation that turns "-<number>" into a single _Num, instead
318-
# of an unary minus applied to a _Num. Here we reverse that.
319-
infstr = "1e" + repr(sys.float_info.max_10_exp + 1)
320-
321-
if isinstance(t.n, complex):
322-
# check that real part is as expected: 0 with appropriate sign
323-
print(t.n)
324-
print(str(t.n.real), str(math.copysign(0.0, t.n.imag)))
325-
assert str(t.n.real) == str(math.copysign(0.0, t.n.imag))
326-
negate = math.copysign(1.0, t.n.imag) < 0
327-
elif isinstance(t.n, float):
328-
negate = math.copysign(1.0, t.n) < 0
329-
elif isinstance(t.n, int):
330-
negate = t.n < 0
331-
332-
if negate:
333-
self.write("(- ")
334-
val = -t.n
314+
if isinstance(t.n, float) and math.isinf(t.n):
315+
# Subsitute overflowing decimal literal for AST infinity
316+
self.write("1e" + repr(sys.float_info.max_10_exp + 1))
335317
else:
336-
val = t.n
337-
338-
# Subsitute an overflowing decimal literal for an AST infinity
339-
self.write(repr(t.n).replace("inf", infstr))
340-
341-
if negate:
342-
self.write(")")
343-
318+
self.write(repr(t.n))
344319

345320
def _List(self, t):
346321
self.write("[")

0 commit comments

Comments
 (0)