49

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.

Sardathrion - against SE abuse
  • 17,269
  • 27
  • 101
  • 156
  • 3
    @tobias_k: `from modile import *` is *really bad practice and should not be used*. On a side note, pylint will complain about that with a `wildcard-import` error. And as you said, `__future__` does not work with wildcard imports. – Sardathrion - against SE abuse Mar 23 '15 at 10:14

1 Answers1

90

Pylint Similarities Config

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
user2357112
  • 260,549
  • 28
  • 431
  • 505
tmthydvnprt
  • 10,398
  • 8
  • 52
  • 72
  • 4
    @Sardathrion Try doing `pylint /path/to/project/ --ignore-imports=no` (*un tested*), but really it is nice to have access to *all* the options from a config file. If you run `pylint --generate-rcfile` that will print out the default options which you can then alter. Just keep the file in the directory of your code. – tmthydvnprt May 05 '15 at 12:13
  • 1
    @Sardathrion or anyone who has a similar issue: We do the same. You can use the argument "--rcfile=tools/pylintrc" when starting pylint from Scons or another script. tools/pylintrc is part of our project tree. – Thomas Giesel Apr 17 '18 at 11:44
  • 2
    set `ignore-imports=yes` to ignore the imports. – Abhishake Gupta Aug 23 '21 at 04:55