diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | pylint/checkers/python3.py | 8 | ||||
-rw-r--r-- | pylint/test/unittest_checker_python3.py | 10 |
3 files changed, 22 insertions, 0 deletions
@@ -4,6 +4,10 @@ Pylint's ChangeLog What's New in Pylint 2.0? ========================= + * Added a new Python 2/3 check for accessing `operator.div`, which is removed in Python 3 + + Close #1936 + * `logging-format-interpolation` also emits when f-strings are used instead of % syntax. Close #1788 diff --git a/pylint/checkers/python3.py b/pylint/checkers/python3.py index ec32f87d3..be83667e5 100644 --- a/pylint/checkers/python3.py +++ b/pylint/checkers/python3.py @@ -448,6 +448,11 @@ class Python3Checker(checkers.BaseChecker): 'Used when dict.values is referenced in a non-iterating ' 'context (returns an iterator in Python 3)', {'maxversion': (3, 0)}), + 'W1657': ('Accessing a removed attribute on the operator module', + 'deprecated-operator-function', + 'Used when accessing a field on operator module that has been ' + 'removed in Python 3.', + {'maxversion': (3, 0)}), } _bad_builtins = frozenset([ @@ -548,6 +553,9 @@ class Python3Checker(checkers.BaseChecker): 'lowercase', 'letters', 'uppercase', 'atol_error', 'atof_error', 'atoi_error', 'index_error' ]) + }, + 'deprecated-operator-function': { + 'operator': frozenset({'div'}), } } diff --git a/pylint/test/unittest_checker_python3.py b/pylint/test/unittest_checker_python3.py index 07fbb7b90..375129815 100644 --- a/pylint/test/unittest_checker_python3.py +++ b/pylint/test/unittest_checker_python3.py @@ -687,6 +687,16 @@ class TestPython3Checker(testutils.CheckerTestCase): self.checker.visit_attribute(node) @python2_only + def test_bad_operator_attribute(self): + node = astroid.extract_node(''' + import operator + operator.div #@ + ''') + message = testutils.Message('deprecated-operator-function', node=node) + with self.assertAddsMessages(message): + self.checker.visit_attribute(node) + + @python2_only def test_ok_string_attribute(self): node = astroid.extract_node(''' import string |