Reputation: 18246
I have this code in (many) of my Python files for a project.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from pprint import pformat
Pylint complains that:
==ook:2
==eek:2
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from pprint import pformat (duplicate-code)
Which while true is utterly irrelevant. The from __future__ [...]
lines are there to prevent compatibility regressions from Python 2 to Python 3. As such, pylint should not complain about them being similar in different files.
Is there a way to stop pytlint doing that?
I know about pylint: disable=duplicate-code
but that will disable it for the whole file because of the import scope. However, I do not want to disable it for the whole file.
Upvotes: 51
Views: 44477
Reputation: 141
You can also disable that pylint check for very specific parts of your codebase where you're sure that you want to keep the duplication:
# pylint: disable=duplicate-code
# Your duplicate lines of code here
# pylint: enable=duplicate-code
Upvotes: 1
Reputation: 10748
Try changing the ignore-imports
in the similarities section of your pylintrc
config file.
Default pylintrc:
[SIMILARITIES]
# Minimum lines number of a similarity.
min-similarity-lines=4
# Ignore comments when computing similarities.
ignore-comments=yes
# Ignore docstrings when computing similarities.
ignore-docstrings=yes
# Ignore imports when computing similarities.
ignore-imports=no
Upvotes: 93