diff options
author | Maksym Humetskyi <Humetsky@gmail.com> | 2021-08-14 05:10:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-14 04:10:53 +0200 |
commit | 37f2f2b51c32537ccabbd2460999e539d50e49f1 (patch) | |
tree | 8da14e38105278b02c2e1e7db0dd204cebe79530 | |
parent | a12242b2f44d5244bd1cacc6bc78df8c9c8e4296 (diff) | |
download | pylint-git-37f2f2b51c32537ccabbd2460999e539d50e49f1.tar.gz |
[duplicate-code] Ignore decorators lines by similarities checker when 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 <mhumets@softserveinc.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
-rw-r--r-- | CONTRIBUTORS.txt | 1 | ||||
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | pylint/checkers/similar.py | 2 | ||||
-rw-r--r-- | tests/checkers/unittest_similar.py | 18 | ||||
-rw-r--r-- | tests/input/similar5 | 6 |
5 files changed, 26 insertions, 5 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 030bb0efc..80e68abb3 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -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 @@ -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? =========================== diff --git a/pylint/checkers/similar.py b/pylint/checkers/similar.py index 5bf55ee78..762ae35b2 100644 --- a/pylint/checkers/similar.py +++ b/pylint/checkers/similar.py @@ -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 diff --git a/tests/checkers/unittest_similar.py b/tests/checkers/unittest_similar.py index db59b00c5..ff3d92ddc 100644 --- a/tests/checkers/unittest_similar.py +++ b/tests/checkers/unittest_similar.py @@ -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, @@ -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() ) @@ -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() ) diff --git a/tests/input/similar5 b/tests/input/similar5 index b6e6b1d0e..0c8bbc2b1 100644 --- a/tests/input/similar5 +++ b/tests/input/similar5 @@ -1,3 +1,9 @@ +@deco1(dval1) +@deco2(dval2) +@deco3( + dval3, + dval4 +) def func1( arg1: int = 3, arg2: Class1 = val1, |