Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
cba8c10b
Kaydet (Commit)
cba8c10b
authored
Haz 30, 2010
tarafından
Mark Dickinson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Unparse infinite imaginary literals correctly. Add some more numeric tests.
üst
abe52d74
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
5 deletions
+20
-5
test_unparse.py
Demo/parser/test_unparse.py
+14
-0
unparse.py
Demo/parser/unparse.py
+6
-5
No files found.
Demo/parser/test_unparse.py
Dosyayı görüntüle @
cba8c10b
...
@@ -123,6 +123,8 @@ class UnparseTestCase(ASTTestCase):
...
@@ -123,6 +123,8 @@ class UnparseTestCase(ASTTestCase):
def
test_unary_parens
(
self
):
def
test_unary_parens
(
self
):
self
.
check_roundtrip
(
"(-1)**7"
)
self
.
check_roundtrip
(
"(-1)**7"
)
self
.
check_roundtrip
(
"(-1.)**8"
)
self
.
check_roundtrip
(
"(-1j)**6"
)
self
.
check_roundtrip
(
"not True or False"
)
self
.
check_roundtrip
(
"not True or False"
)
self
.
check_roundtrip
(
"True or not False"
)
self
.
check_roundtrip
(
"True or not False"
)
...
@@ -132,6 +134,18 @@ class UnparseTestCase(ASTTestCase):
...
@@ -132,6 +134,18 @@ class UnparseTestCase(ASTTestCase):
def
test_huge_float
(
self
):
def
test_huge_float
(
self
):
self
.
check_roundtrip
(
"1e1000"
)
self
.
check_roundtrip
(
"1e1000"
)
self
.
check_roundtrip
(
"-1e1000"
)
self
.
check_roundtrip
(
"-1e1000"
)
self
.
check_roundtrip
(
"1e1000j"
)
self
.
check_roundtrip
(
"-1e1000j"
)
def
test_min_int
(
self
):
self
.
check_roundtrip
(
str
(
-
2
**
31
))
self
.
check_roundtrip
(
str
(
-
2
**
63
))
def
test_imaginary_literals
(
self
):
self
.
check_roundtrip
(
"7j"
)
self
.
check_roundtrip
(
"-7j"
)
self
.
check_roundtrip
(
"0j"
)
self
.
check_roundtrip
(
"-0j"
)
def
test_lambda_parentheses
(
self
):
def
test_lambda_parentheses
(
self
):
self
.
check_roundtrip
(
"(lambda: int)()"
)
self
.
check_roundtrip
(
"(lambda: int)()"
)
...
...
Demo/parser/unparse.py
Dosyayı görüntüle @
cba8c10b
...
@@ -6,6 +6,10 @@ import tokenize
...
@@ -6,6 +6,10 @@ import tokenize
import
io
import
io
import
os
import
os
# Large float and imaginary literals get turned into infinities in the AST.
# We unparse those infinities to INFSTR.
INFSTR
=
"1e"
+
repr
(
sys
.
float_info
.
max_10_exp
+
1
)
def
interleave
(
inter
,
f
,
seq
):
def
interleave
(
inter
,
f
,
seq
):
"""Call f on each item in seq, calling inter() in between.
"""Call f on each item in seq, calling inter() in between.
"""
"""
...
@@ -311,11 +315,8 @@ class Unparser:
...
@@ -311,11 +315,8 @@ class Unparser:
self
.
write
(
t
.
id
)
self
.
write
(
t
.
id
)
def
_Num
(
self
,
t
):
def
_Num
(
self
,
t
):
if
isinstance
(
t
.
n
,
float
)
and
math
.
isinf
(
t
.
n
):
# Substitute overflowing decimal literal for AST infinities.
# Subsitute overflowing decimal literal for AST infinity
self
.
write
(
repr
(
t
.
n
)
.
replace
(
"inf"
,
INFSTR
))
self
.
write
(
"1e"
+
repr
(
sys
.
float_info
.
max_10_exp
+
1
))
else
:
self
.
write
(
repr
(
t
.
n
))
def
_List
(
self
,
t
):
def
_List
(
self
,
t
):
self
.
write
(
"["
)
self
.
write
(
"["
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment