Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pylint duplicate code false positive

Tags:

python

pylint

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.

like image 976
Sardathrion - against SE abuse Avatar asked Mar 23 '15 09:03

Sardathrion - against SE abuse


1 Answers

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
like image 126
tmthydvnprt Avatar answered Oct 18 '22 23:10

tmthydvnprt