Skip to content

Commit 996b3fb

Browse files
millerdevPCManticore
authored andcommitted
Respect disable=... in config with --py3k (#1726)
1 parent 99abc89 commit 996b3fb

File tree

5 files changed

+65
-12
lines changed

5 files changed

+65
-12
lines changed

ChangeLog

+1-12
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,7 @@ Pylint's ChangeLog
44
What's New in Pylint 1.8?
55
=========================
66

7-
* New warning `shallow-copy-environ` added
8-
9-
Shallow copy of os.environ doesn't work as people may expect. os.environ
10-
is not a dict object but rather a proxy object, so any changes made
11-
on copy may have unexpected effects on os.environ
12-
13-
Instead of copy.copy(os.environ) method os.environ.copy() should be
14-
used.
15-
16-
See https://bugs.python.org/issue15373 for details.
17-
18-
Close #1301
7+
* Respect disable=... in config file when running with --py3k.
198

209
* Do not display no-absolute-import warning multiple times per file.
2110

pylint/lint.py

+8
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,10 @@ def error_mode(self):
595595
for msg_id in self._checker_messages('python3'):
596596
if msg_id.startswith('E'):
597597
self.enable(msg_id)
598+
config_parser = self.cfgfile_parser
599+
if config_parser.has_option('MESSAGES CONTROL', 'disable'):
600+
value = config_parser.get('MESSAGES CONTROL', 'disable')
601+
self.global_set_option('disable', value)
598602
else:
599603
self.disable('python3')
600604
self.set_option('reports', False)
@@ -614,6 +618,10 @@ def python3_porting_mode(self):
614618
self.enable(msg_id)
615619
else:
616620
self.disable(msg_id)
621+
config_parser = self.cfgfile_parser
622+
if config_parser.has_option('MESSAGES CONTROL', 'disable'):
623+
value = config_parser.get('MESSAGES CONTROL', 'disable')
624+
self.global_set_option('disable', value)
617625
self._python3_porting_mode = True
618626

619627
# block level option handling #############################################
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[MESSAGES CONTROL]
2+
disable=no-absolute-import
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""Contains both normal error messages and Python3 porting error messages."""
2+
# pylint: disable=too-few-public-methods
3+
4+
# error: import missing `from __future__ import absolute_import`
5+
import sys
6+
7+
# error: Use raise ErrorClass(args) instead of raise ErrorClass, args.
8+
raise Exception, 1
9+
10+
class Test(object):
11+
"""dummy"""
12+
13+
def __init__(self):
14+
# warning: Calling a dict.iter*() method
15+
{1: 2}.iteritems()
16+
return 42
17+
18+
# error: print statement used
19+
print 'not in python3'

pylint/test/test_self.py

+35
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,41 @@ def test_py3k_commutative_with_errors_only(self):
237237
self._test_output([module, "--py3k", "-E", "--msg-template='{msg}'"],
238238
expected_output=expected)
239239

240+
@pytest.mark.skipif(sys.version_info[0] > 2, reason="Requires the --py3k flag.")
241+
def test_py3k_commutative_with_config_disable(self):
242+
module = join(HERE, 'regrtest_data', 'py3k_errors_and_warnings.py')
243+
rcfile = join(HERE, 'regrtest_data', 'py3k-disabled.rc')
244+
cmd = [module, "--msg-template='{msg}'", "--reports=n"]
245+
246+
expected = textwrap.dedent("""
247+
************* Module py3k_errors_and_warnings
248+
import missing `from __future__ import absolute_import`
249+
Use raise ErrorClass(args) instead of raise ErrorClass, args.
250+
Calling a dict.iter*() method
251+
print statement used
252+
""")
253+
self._test_output(cmd + ["--py3k"], expected_output=expected)
254+
255+
expected = textwrap.dedent("""
256+
************* Module py3k_errors_and_warnings
257+
Use raise ErrorClass(args) instead of raise ErrorClass, args.
258+
Calling a dict.iter*() method
259+
print statement used
260+
""")
261+
self._test_output(cmd + ["--py3k", "--rcfile", rcfile],
262+
expected_output=expected)
263+
264+
expected = textwrap.dedent("""
265+
************* Module py3k_errors_and_warnings
266+
Use raise ErrorClass(args) instead of raise ErrorClass, args.
267+
print statement used
268+
""")
269+
self._test_output(cmd + ["--py3k", "-E", "--rcfile", rcfile],
270+
expected_output=expected)
271+
272+
self._test_output(cmd + ["-E", "--py3k", "--rcfile", rcfile],
273+
expected_output=expected)
274+
240275
def test_abbreviations_are_not_supported(self):
241276
expected = "no such option: --load-plugin"
242277
self._test_output([".", "--load-plugin"], expected_output=expected)

0 commit comments

Comments
 (0)