diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2018-05-11 22:00:57 -0400 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-05-11 22:00:57 -0400 |
commit | cc40b93c4d071136b822fd49b87c7fac15a51617 (patch) | |
tree | 323dfc8bed8d9241c2ec6bccd732e03700afcc61 | |
parent | 6146ce636a7117a78a3e8f746762f477f603dae4 (diff) | |
download | pylint-git-cc40b93c4d071136b822fd49b87c7fac15a51617.tar.gz |
Emit a warning when sys.exc_clear is accessed
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | doc/whatsnew/1.9.rst | 5 | ||||
-rw-r--r-- | pylint/checkers/python3.py | 7 | ||||
-rw-r--r-- | pylint/test/unittest_checker_python3.py | 9 |
4 files changed, 23 insertions, 0 deletions
@@ -8,6 +8,8 @@ What's New in Pylint 1.9.0? Release date: + * Added a new `deprecated-sys-function`, emitted when accessing removed sys members. + * Added `xreadlines-attribute`, emitted when the `xreadlines()` attribute is accessed. * The Python 3 porting mode can now run with Python 3 as well. diff --git a/doc/whatsnew/1.9.rst b/doc/whatsnew/1.9.rst index f9e60111f..a15658dd4 100644 --- a/doc/whatsnew/1.9.rst +++ b/doc/whatsnew/1.9.rst @@ -45,6 +45,11 @@ New checkers a = ur'...' +* Added a new `deprecated-sys-function`, emitted when accessing removed `sys` members. + +* Added `xreadlines-attribute`, emitted when the `xreadlines()` attribute is accessed + on a file object. + Other Changes ============= diff --git a/pylint/checkers/python3.py b/pylint/checkers/python3.py index b9e1e299e..111d9bde9 100644 --- a/pylint/checkers/python3.py +++ b/pylint/checkers/python3.py @@ -409,6 +409,10 @@ class Python3Checker(checkers.BaseChecker): 'xreadlines-attribute', 'Used when accessing the xreadlines() function on a file stream, ' 'removed in Python 3.',), + 'W1660': ('Accessing a removed attribute on the sys module', + 'deprecated-sys-function', + 'Used when accessing a field on sys module that has been ' + 'removed in Python 3.',), } _bad_builtins = frozenset([ @@ -526,6 +530,9 @@ class Python3Checker(checkers.BaseChecker): 'urlopen', 'urlretrieve' }), }, + 'deprecated-sys-function': { + 'sys': frozenset({'exc_clear'}), + } } if (3, 4) <= sys.version_info < (3, 4, 4): diff --git a/pylint/test/unittest_checker_python3.py b/pylint/test/unittest_checker_python3.py index c5800f493..6f8b57944 100644 --- a/pylint/test/unittest_checker_python3.py +++ b/pylint/test/unittest_checker_python3.py @@ -717,6 +717,15 @@ class TestPython3Checker(testutils.CheckerTestCase): with self.assertAddsMessages(message): self.checker.visit_attribute(node) + def test_bad_sys_attribute(self): + node = astroid.extract_node(''' + import sys + sys.exc_clear #@ + ''') + message = testutils.Message('deprecated-sys-function', node=node) + with self.assertAddsMessages(message): + self.checker.visit_attribute(node) + def test_bad_urllib_attribute(self): nodes = astroid.extract_node(''' import urllib |