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
608adf9c
Kaydet (Commit)
608adf9c
authored
Eyl 20, 2015
tarafından
Eric V. Smith
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue 25180: Fix Tools/parser/unparse.py for f-strings. Patch by Martin Panter.
üst
57b65793
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
2 deletions
+48
-2
test_unparse.py
Lib/test/test_tools/test_unparse.py
+9
-2
unparse.py
Tools/parser/unparse.py
+39
-0
No files found.
Lib/test/test_tools/test_unparse.py
Dosyayı görüntüle @
608adf9c
...
...
@@ -134,6 +134,15 @@ class ASTTestCase(unittest.TestCase):
class
UnparseTestCase
(
ASTTestCase
):
# Tests for specific bugs found in earlier versions of unparse
def
test_fstrings
(
self
):
# See issue 25180
self
.
check_roundtrip
(
r"""f'{f"{0}"*3}'"""
)
self
.
check_roundtrip
(
r"""f'{f"{y}"*3}'"""
)
self
.
check_roundtrip
(
r"""f'{f"{\'x\'}"*3}'"""
)
self
.
check_roundtrip
(
r'''f"{r'x' f'{\"s\"}'}"'''
)
self
.
check_roundtrip
(
r'''f"{r'x'rf'{\"s\"}'}"'''
)
def
test_del_statement
(
self
):
self
.
check_roundtrip
(
"del x, y, z"
)
...
...
@@ -264,8 +273,6 @@ class DirectoryTestCase(ASTTestCase):
for
d
in
self
.
test_directories
:
test_dir
=
os
.
path
.
join
(
basepath
,
d
)
for
n
in
os
.
listdir
(
test_dir
):
if
n
==
'test_fstring.py'
:
continue
if
n
.
endswith
(
'.py'
)
and
not
n
.
startswith
(
'bad'
):
names
.
append
(
os
.
path
.
join
(
test_dir
,
n
))
...
...
Tools/parser/unparse.py
Dosyayı görüntüle @
608adf9c
...
...
@@ -322,6 +322,45 @@ class Unparser:
def
_Str
(
self
,
tree
):
self
.
write
(
repr
(
tree
.
s
))
def
_JoinedStr
(
self
,
t
):
self
.
write
(
"f"
)
string
=
io
.
StringIO
()
self
.
_fstring_JoinedStr
(
t
,
string
.
write
)
self
.
write
(
repr
(
string
.
getvalue
()))
def
_FormattedValue
(
self
,
t
):
self
.
write
(
"f"
)
string
=
io
.
StringIO
()
self
.
_fstring_FormattedValue
(
t
,
string
.
write
)
self
.
write
(
repr
(
string
.
getvalue
()))
def
_fstring_JoinedStr
(
self
,
t
,
write
):
for
value
in
t
.
values
:
meth
=
getattr
(
self
,
"_fstring_"
+
type
(
value
)
.
__name__
)
meth
(
value
,
write
)
def
_fstring_Str
(
self
,
t
,
write
):
value
=
t
.
s
.
replace
(
"{"
,
"{{"
)
.
replace
(
"}"
,
"}}"
)
write
(
value
)
def
_fstring_FormattedValue
(
self
,
t
,
write
):
write
(
"{"
)
expr
=
io
.
StringIO
()
Unparser
(
t
.
value
,
expr
)
expr
=
expr
.
getvalue
()
.
rstrip
(
"
\n
"
)
if
expr
.
startswith
(
"{"
):
write
(
" "
)
# Separate pair of opening brackets as "{ {"
write
(
expr
)
if
t
.
conversion
!=
-
1
:
conversion
=
chr
(
t
.
conversion
)
assert
conversion
in
"sra"
write
(
f
"!{conversion}"
)
if
t
.
format_spec
:
write
(
":"
)
meth
=
getattr
(
self
,
"_fstring_"
+
type
(
t
.
format_spec
)
.
__name__
)
meth
(
t
.
format_spec
,
write
)
write
(
"}"
)
def
_Name
(
self
,
t
):
self
.
write
(
t
.
id
)
...
...
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