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
c2bf723a
Kaydet (Commit)
c2bf723a
authored
Tem 16, 2017
tarafından
Anthony Sottile
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Remove automatic py35+ syntax detection
üst
30d7eb8a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
42 deletions
+6
-42
README.md
README.md
+2
-2
add_trailing_comma.py
add_trailing_comma.py
+4
-22
add_trailing_comma_test.py
tests/add_trailing_comma_test.py
+0
-18
No files found.
README.md
Dosyayı görüntüle @
c2bf723a
...
...
@@ -86,8 +86,8 @@ This has the following benefits:
### trailing commas for function calls with unpackings
If
`--py35-plus`
is passed
(or python3.5+ syntax is automatically detected),
`add-trailing-comma`
will also perform the
following change:
If
`--py35-plus`
is passed
,
`add-trailing-comma`
will also perform the
following change:
```
diff
x(
...
...
add_trailing_comma.py
Dosyayı görüntüle @
c2bf723a
...
...
@@ -62,24 +62,16 @@ class FindNodes(ast.NodeVisitor):
self
.
calls
=
{}
self
.
funcs
=
{}
self
.
literals
=
{}
self
.
has_new_syntax
=
False
def
_visit_literal
(
self
,
node
,
key
=
'elts'
,
**
kwargs
):
for
elt
in
getattr
(
node
,
key
):
if
_is_star_arg
(
elt
):
# pragma: no cover (PY35+)
self
.
has_new_syntax
=
True
if
getattr
(
node
,
key
):
key
=
Offset
(
node
.
lineno
,
node
.
col_offset
)
self
.
literals
[
key
]
=
Literal
(
node
,
**
kwargs
)
self
.
generic_visit
(
node
)
self
.
generic_visit
(
node
)
visit_Set
=
visit_List
=
_visit_literal
def
visit_Dict
(
self
,
node
):
# unpackings are represented as a `None` key
if
None
in
node
.
keys
:
# pragma: no cover (PY35+)
self
.
has_new_syntax
=
True
self
.
_visit_literal
(
node
,
key
=
'values'
)
def
visit_Tuple
(
self
,
node
):
...
...
@@ -119,12 +111,6 @@ class FindNodes(ast.NodeVisitor):
key
=
Offset
(
node
.
lineno
,
node
.
col_offset
)
self
.
calls
[
key
]
=
Call
(
node
,
has_starargs
,
arg_offsets
)
if
(
sum
(
_is_star_arg
(
n
)
for
n
in
node
.
args
)
>
1
or
sum
(
_is_star_star_kwarg
(
n
)
for
n
in
node
.
keywords
)
>
1
):
# pragma: no cover (PY35+)
self
.
has_new_syntax
=
True
self
.
generic_visit
(
node
)
def
visit_FunctionDef
(
self
,
node
):
...
...
@@ -134,14 +120,11 @@ class FindNodes(ast.NodeVisitor):
getattr
(
node
.
args
,
'kwonlyargs'
,
None
)
)
offsets
=
set
()
for
argnode
in
node
.
args
.
args
:
offset
=
_to_offset
(
argnode
)
offsets
.
add
(
offset
)
arg_offsets
=
{
_to_offset
(
arg
)
for
arg
in
node
.
args
.
args
}
if
offsets
and
not
has_starargs
:
if
arg_
offsets
and
not
has_starargs
:
key
=
Offset
(
node
.
lineno
,
node
.
col_offset
)
self
.
funcs
[
key
]
=
Func
(
node
,
offsets
)
self
.
funcs
[
key
]
=
Func
(
node
,
arg_
offsets
)
self
.
generic_visit
(
node
)
...
...
@@ -325,7 +308,6 @@ def _fix_src(contents_text, py35_plus):
visitor
=
FindNodes
()
visitor
.
visit
(
ast_obj
)
py35_plus
=
py35_plus
or
visitor
.
has_new_syntax
tokens
=
src_to_tokens
(
contents_text
)
for
i
,
token
in
_changing_list
(
tokens
):
...
...
tests/add_trailing_comma_test.py
Dosyayı görüntüle @
c2bf723a
...
...
@@ -84,24 +84,6 @@ def test_py35_plus_rewrite():
)
@xfailif_lt_py35
@pytest.mark.parametrize
(
'syntax'
,
(
'(1, 2, *a)
\n
'
,
'[1, 2, *a]
\n
'
,
'{1, 2, *a}
\n
'
,
'{1: 2, **k}
\n
'
,
'y(*args1, *args2)
\n
'
,
'y(**kwargs1, **kwargs2)
\n
'
,
),
)
def
test_auto_detected_py35_plus_rewrite
(
syntax
):
src
=
syntax
+
'x(
\n
*args
\n
)'
expected
=
syntax
+
'x(
\n
*args,
\n
)'
assert
_fix_src
(
src
,
py35_plus
=
False
)
==
expected
@pytest.mark.parametrize
(
(
'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