Skip to content

Commit

Permalink
[duplicate-code] Ignore decorators lines by similarities checker when…
Browse files Browse the repository at this point in the history
… ignore signatures flag enabled (#4840)

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: Maksym Humetskyi <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 14, 2021
1 parent a12242b commit 37f2f2b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
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

0 comments on commit 37f2f2b

Please sign in to comment.