Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
A
astor
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
astor
Commits
ee09ae42
Kaydet (Commit)
ee09ae42
authored
Haz 22, 2018
tarafından
Kodi Arfer
Kaydeden (comit)
Berker Peksag
Haz 22, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Generate correct code for empty sets (#112)
Closes #108
üst
991e6e94
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
3 deletions
+25
-3
code_gen.py
astor/code_gen.py
+8
-2
changelog.rst
docs/changelog.rst
+5
-0
test_code_gen.py
tests/test_code_gen.py
+12
-1
No files found.
astor/code_gen.py
Dosyayı görüntüle @
ee09ae42
...
...
@@ -663,8 +663,14 @@ class SourceGenerator(ExplicitNodeVisitor):
self
.
comma_list
(
node
.
elts
)
def
visit_Set
(
self
,
node
):
with
self
.
delimit
(
'{}'
):
self
.
comma_list
(
node
.
elts
)
if
node
.
elts
:
with
self
.
delimit
(
'{}'
):
self
.
comma_list
(
node
.
elts
)
else
:
# If we tried to use "{}" to represent an empty set, it would be
# interpreted as an empty dictionary. We can't use "set()" either
# because the name "set" might be rebound.
self
.
write
(
'{1}.__class__()'
)
def
visit_Dict
(
self
,
node
):
set_precedence
(
Precedence
.
Comma
,
*
node
.
values
)
...
...
docs/changelog.rst
Dosyayı görüntüle @
ee09ae42
...
...
@@ -42,6 +42,11 @@ Bug fixes
.. _`Issue 85`: https://github.com/berkerpeksag/astor/issues/85
.. _`Issue 100`: https://github.com/berkerpeksag/astor/issues/100
* Improved code generation to support empty sets.
(Reported and fixed by Kodi Arfer in `Issue 108`_.)
.. _`Issue 108`: https://github.com/berkerpeksag/astor/issues/108
0.6.2 - 2017-11-11
------------------
...
...
tests/test_code_gen.py
Dosyayı görüntüle @
ee09ae42
...
...
@@ -23,8 +23,11 @@ import astor
def
canonical
(
srctxt
):
return
textwrap
.
dedent
(
srctxt
)
.
strip
()
def
astorexpr
(
x
):
return
eval
(
astor
.
to_source
(
ast
.
Expression
(
body
=
x
)))
def
astornum
(
x
):
return
eval
(
astor
.
to_source
(
ast
.
Expression
(
body
=
ast
.
Num
(
n
=
x
))
))
return
astorexpr
(
ast
.
Num
(
n
=
x
))
class
Comparisons
(
object
):
...
...
@@ -93,6 +96,14 @@ class CodegenTestCase(unittest.TestCase, Comparisons):
source
=
"from ..aaa import foo, bar as bar2"
self
.
assertSrcRoundtrips
(
source
)
def
test_empty_iterable_literals
(
self
):
self
.
assertSrcRoundtrips
(
'()'
)
self
.
assertSrcRoundtrips
(
'[]'
)
self
.
assertSrcRoundtrips
(
'{}'
)
# Python has no literal for empty sets, but code_gen should produce an
# expression that evaluates to one.
self
.
assertEqual
(
astorexpr
(
ast
.
Set
([])),
set
())
def
test_dictionary_literals
(
self
):
source
=
"{'a': 1, 'b': 2}"
self
.
assertSrcRoundtrips
(
source
)
...
...
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