Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[duplicate-code] Ignore decorators lines by similarities checker when ignore signatures flag enabled #4840

Merged
merged 2 commits into from
Aug 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ contributors:

* Maksym Humetskyi (mhumetskyi): contributor
- Fixed ignored empty functions by similarities checker with "ignore-signatures" option enabled
- Ignore function decorators signatures as well by similarities checker with "ignore-signatures" option enabled

* Daniel Dorani (doranid): contributor

Expand Down
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ Release date: TBA

* Emit ``consider-using-tuple`` even if list contains a ``starred`` expression.

* Ignore decorators lines by similarities checker when ignore signatures flag enabled

Closes #4839


What's New in Pylint 2.9.6?
===========================
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/similar.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ def stripped_lines(
chain(
*(
range(
func.fromlineno,
func.lineno,
func.body[0].lineno if func.body else func.tolineno + 1,
)
for func in functions
Expand Down
18 changes: 14 additions & 4 deletions tests/checkers/unittest_similar.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_ignore_signatures_fail():
== (
'''
9 similar lines in 2 files
==%s:[1:11]
==%s:[7:17]
==%s:[8:18]
arg1: int = 3,
arg2: Class1 = val1,
Expand All @@ -183,9 +183,19 @@ def test_ignore_signatures_fail():

def example():
"""Valid function definition with docstring only."""
TOTAL lines=29 duplicates=9 percent=31.03

6 similar lines in 2 files
==%s:[0:6]
==%s:[1:7]
@deco1(dval1)
@deco2(dval2)
@deco3(
dval3,
dval4
)
TOTAL lines=35 duplicates=15 percent=42.86
'''
% (SIMILAR5, SIMILAR6)
% (SIMILAR5, SIMILAR6, SIMILAR5, SIMILAR6)
).strip()
)

Expand All @@ -198,7 +208,7 @@ def test_ignore_signatures_pass():
assert (
output.getvalue().strip()
== """
TOTAL lines=29 duplicates=0 percent=0.00
TOTAL lines=35 duplicates=0 percent=0.00
""".strip()
)

Expand Down
6 changes: 6 additions & 0 deletions tests/input/similar5
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
@deco1(dval1)
@deco2(dval2)
@deco3(
dval3,
dval4
)
def func1(
arg1: int = 3,
arg2: Class1 = val1,
Expand Down