-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 warning occurs for multiline imports even with ignore-imports=yes #2019
Comments
Thanks for the report! I can reproduce the issue. From a short glance, it seems we don't quite handle correctly |
Perhaps what should really happen is well right before the actual code that reports it as a issue have a
So that way it does not clutter code with a ton of hacks. I know from experience (look at my failure repos at https://github.com/DecoraterBot-devs/). But @PCManticore everyone in python 3.x do this sort of import and star imports from modules, I think the reports from those on python 3 code should not happen even without ignore-imports=yes, maybe python 2 but I do not think so on 3. Even some places of the python standard library uses it so I personally think it is not only useless but dumb to scan for if the resulting code is python 3. |
The duplicate code checks cover more than imports, so suppressing all duplicate code warnings if the flag is set would be incorrect. I believe that the problem as described is that I have not looked at the code yet however it seems like it would be very difficult to achieve linting without parsing the code. The solution that I see is to ensure that this operates over the logical import statement rather than the line starting |
Or maybe check to see if the import line has a "(" and ignore every line within that until it finds the other ")"? |
That's basically implementing a parser. Pylint uses ast which is a full python parser. |
pylint uses a parser elsewhere, but the Similar / symilar / duplicate-code / R0801 check does not use a parser. --ignore-imports is implemented in stripped_lines() in pylint/checkers/similar.py like this:
I agree, it should use a real parser. This and #1422 appear to describe the same issue. |
Fix R0801, pylint-dev/pylint#2019
Steps to reproduce
a.py
b.py
c.py
Place them in a folder called
src
that contains an__init__.py
file.Run pylint over them:
pylint src/*.py
Run pylint over them, using the ignore-imports option:
pylint --ignore-imports=yes src/*.py
Current behavior
Expected behavior
The duplicate lines are import statements that have been wrapped onto multiple lines.
They should not trigger the similarity checker when the
--ignore-imports=yes
option is used.pylint --version output
The text was updated successfully, but these errors were encountered: