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

pylint will not report duplicate code within same file unless multiple files are checked. #2697

Closed
lschrof-maestrohealth opened this issue Jan 18, 2019 · 4 comments
Labels
Duplicate 🐫 Duplicate of an already existing issue

Comments

@lschrof-maestrohealth
Copy link

lschrof-maestrohealth commented Jan 18, 2019

First, it is important to acknowledge that duplicate code within an individual python file can be detrimental and need to be cleaned up / refactored, just as is the case with duplicate code spanning multiple files. If you disagree with this, you can close this issue now.

Applying the DRY principle (don't repeat yourself) to code is great, and pylint helps with this.
pylint is capable of finding duplicate code within the same file, but the problem is that pylint won't report this unless multiple files are checked.

Steps to reproduce

  1. Create a file where several lines of code are duplicated, call this foo.py
  2. Create a second python file with non-empty python content, ensuring that the duplicate code from foo.py does not happen to also exist in the file; call this bar.py
  3. Run pylint twice. The first time, run it on both foo.py and bar.py. The second time, run it only on foo.py.

You will notice that in the first run, pylint is perfectly able to find and report on duplicate code occurrences within the same individual file, which is fantastic. However, you will notice that in the second run, the reporting of the duplicate code has disappeared.

So we know that pylint can find duplicate code within an individual file, but it doesn't always report it. From best I can tell, the way to trigger the bug is to tell it to check only one file.

Current behavior

pylint will only report duplicate code within the same file if multiple files are being checked.

Expected behavior

pylint will report duplicate code within the same file regardless of how many files pylint has been asked to check. (one vs. more than one)

pylint --version output

pylint 2.2.2
astroid 2.0.4
Python 3.6.5 (default, Apr 25 2018, 14:23:58)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]

@PCManticore
Copy link
Contributor

Hey @lschrof-maestrohealth Thanks for reporting this issue! yes, this makes sense and it would be great to support this use case as well.

@PCManticore PCManticore added the Enhancement ✨ Improvement to a component label Feb 18, 2019
@LoicH
Copy link

LoicH commented Mar 8, 2022

Hi, any news on this feature? :)

@orSolocate
Copy link
Contributor

@LoicH I could try to reproduce it on the latest version and look if can be solved easily

@Pierre-Sassoulas
Copy link
Member

Closing as a duplicate of #1457

@Pierre-Sassoulas Pierre-Sassoulas closed this as not planned Won't fix, can't repro, duplicate, stale Sep 10, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Duplicate 🐫 Duplicate of an already existing issue and removed Enhancement ✨ Improvement to a component labels Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🐫 Duplicate of an already existing issue
Projects
None yet
Development

No branches or pull requests

5 participants