Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
A
add-trailing-comma
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
add-trailing-comma
Commits
7c66adc9
Kaydet (Commit)
7c66adc9
authored
Tem 17, 2017
tarafından
Anthony Sottile
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Handle multiple functions in the same starting position
üst
47aa870c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
16 deletions
+24
-16
add_trailing_comma.py
add_trailing_comma.py
+14
-16
add_trailing_comma_test.py
tests/add_trailing_comma_test.py
+10
-0
No files found.
add_trailing_comma.py
Dosyayı görüntüle @
7c66adc9
...
...
@@ -59,7 +59,8 @@ def _is_star_star_kwarg(node):
class
FindNodes
(
ast
.
NodeVisitor
):
def
__init__
(
self
):
self
.
calls
=
{}
# multiple calls can report their starting position as the same
self
.
calls
=
collections
.
defaultdict
(
list
)
self
.
funcs
=
{}
self
.
literals
=
{}
...
...
@@ -109,7 +110,7 @@ class FindNodes(ast.NodeVisitor):
if
arg_offsets
and
not
only_a_generator
:
key
=
Offset
(
node
.
lineno
,
node
.
col_offset
)
self
.
calls
[
key
]
=
Call
(
node
,
has_starargs
,
arg_offsets
)
self
.
calls
[
key
]
.
append
(
Call
(
node
,
has_starargs
,
arg_offsets
)
)
self
.
generic_visit
(
node
)
...
...
@@ -312,33 +313,30 @@ def _fix_src(contents_text, py35_plus):
tokens
=
src_to_tokens
(
contents_text
)
for
i
,
token
in
_changing_list
(
tokens
):
key
=
Offset
(
token
.
line
,
token
.
utf8_byte_offset
)
add_comma
=
True
fix_data
=
None
fixes
=
[]
if
key
in
visitor
.
calls
:
call
=
visitor
.
calls
[
key
]
# Only fix stararg calls if asked to
add_comma
=
not
call
.
star_args
or
py35_plus
fix_data
=
_find_call
(
call
,
i
,
tokens
)
for
call
in
visitor
.
calls
[
key
]:
# Only fix stararg calls if asked to
add_comma
=
not
call
.
star_args
or
py35_plus
fixes
.
append
((
add_comma
,
_find_call
(
call
,
i
,
tokens
))
)
elif
key
in
visitor
.
funcs
:
func
=
visitor
.
funcs
[
key
]
# functions can be treated as calls
fix
_data
=
_find_call
(
func
,
i
,
tokens
)
fix
es
.
append
((
True
,
_find_call
(
visitor
.
funcs
[
key
],
i
,
tokens
))
)
# Handle parenthesized things
elif
token
.
src
==
'('
:
fix_data
=
_find_simple
(
i
,
tokens
)
add_comma
=
False
if
fix_data
is
not
None
:
_fix_brace
(
fix_data
,
add_comma
,
tokens
)
fixes
.
append
((
False
,
_find_simple
(
i
,
tokens
)))
# need to additionally handle literals afterwards as tuples report
# their starting index as the first element, which may be one of the
# above things.
if
key
in
visitor
.
literals
:
fix_data
=
_find_literal
(
visitor
.
literals
[
key
],
i
,
tokens
)
fixes
.
append
((
True
,
fix_data
))
for
add_comma
,
fix_data
in
fixes
:
if
fix_data
is
not
None
:
_fix_brace
(
fix_data
,
True
,
tokens
)
_fix_brace
(
fix_data
,
add_comma
,
tokens
)
return
tokens_to_src
(
tokens
)
...
...
tests/add_trailing_comma_test.py
Dosyayı görüntüle @
7c66adc9
...
...
@@ -114,6 +114,16 @@ def test_py35_plus_rewrite():
' 1,
\n
'
')'
,
),
# Regression test for #22
(
'x({}).y(
\n
'
' x
\n
'
')'
,
'x({}).y(
\n
'
' x,
\n
'
')'
,
),
),
)
def
test_fixes_calls
(
src
,
expected
):
...
...
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