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
3eb02903
Kaydet (Commit)
3eb02903
authored
Haz 29, 2010
tarafından
Mark Dickinson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add parentheses around numeric literals, to avoid turning 3 .bit_length() into 3.bit_length().
üst
82c8d933
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
10 deletions
+14
-10
test_unparse.py
Demo/parser/test_unparse.py
+3
-0
unparse.py
Demo/parser/unparse.py
+11
-10
No files found.
Demo/parser/test_unparse.py
Dosyayı görüntüle @
3eb02903
...
...
@@ -84,6 +84,9 @@ class UnparseTestCase(unittest.TestCase):
self
.
check_roundtrip
(
"not True or False"
)
self
.
check_roundtrip
(
"True or not False"
)
def
test_integer_parens
(
self
):
self
.
check_roundtrip
(
"3 .__abs__()"
)
def
test_chained_comparisons
(
self
):
self
.
check_roundtrip
(
"1 < 4 <= 5"
)
self
.
check_roundtrip
(
"a is b is c is not d"
)
...
...
Demo/parser/unparse.py
Dosyayı görüntüle @
3eb02903
...
...
@@ -302,16 +302,17 @@ class Unparser:
self
.
write
(
"`"
)
def
_Num
(
self
,
t
):
# There are no negative numeric literals in Python; however,
# some optimizations produce a negative Num in the AST. Add
# parentheses to avoid turning (-1)**2 into -1**2.
strnum
=
repr
(
t
.
n
)
if
strnum
.
startswith
(
"-"
):
self
.
write
(
"("
)
self
.
write
(
strnum
)
self
.
write
(
")"
)
else
:
self
.
write
(
strnum
)
# Add parentheses around numeric literals to avoid:
#
# (1) turning (-1)**2 into -1**2, and
# (2) turning 3 .__abs__() into 3.__abs__()
#
# For (1), note that Python doesn't actually have negative
# numeric literals, but (at least in Python 2.x) there's a CST
# transformation that can produce negative Nums in the AST.
self
.
write
(
"("
)
self
.
write
(
repr
(
t
.
n
))
self
.
write
(
")"
)
def
_List
(
self
,
t
):
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