From 0624e39d8ef1d74d4d41cf71d94ac1e138865736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20L=C3=B3pez?= Date: Wed, 4 May 2016 17:03:24 -0500 Subject: [PATCH] [IMP] duplicate-code: Add feature to disable a duplicate-code from pylint: disable comment --- pylint/checkers/similar.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pylint/checkers/similar.py b/pylint/checkers/similar.py index fe0d90567f..6666831038 100644 --- a/pylint/checkers/similar.py +++ b/pylint/checkers/similar.py @@ -303,6 +303,13 @@ def process_module(self, node): stream, node.file_encoding) + def _is_disabled_comment(self, lines): + for line in lines: + # TODO: Better way of get a disabled comment from a string + if ('R0801' in line or 'duplicate-code' in line) and ('pylint' in line and 'disable' in line): + return True + return False + def close(self): """compute and display similarities on closing (i.e. end of parsing)""" total = sum(len(lineset) for lineset in self.linesets) @@ -311,7 +318,10 @@ def close(self): for num, couples in self._compute_sims(): msg = [] for lineset, idx in couples: - msg.append("==%s:%s" % (lineset.name, idx)) + if not self._is_disabled_comment(lineset._real_lines): + msg.append("==%s:%s" % (lineset.name, idx)) + if len(msg) < 2: + continue msg.sort() # pylint: disable=W0631 for line in lineset._real_lines[idx:idx+num]: