summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatalie Serebryakova <natalie.serebryakova@Natalies-MacBook-Pro.local>2018-05-16 00:41:24 -0400
committerClaudiu Popa <pcmanticore@gmail.com>2018-08-15 20:17:59 +0200
commit41d47dd024a3fe6a1c67ebf32c8dc6ee24a44f66 (patch)
tree2e0939ad2488039a0665199b2ef785dbb829bd3b
parent29cacf3c5a09f08aa91dfd7d45f508088ce9317b (diff)
downloadpylint-git-41d47dd024a3fe6a1c67ebf32c8dc6ee24a44f66.tar.gz
Remove a couple of Python 2 specific checks
The Removed Python 2 specific checks are: deprecated-lambda, nonstandard-exception, lowercase-l-suffix, slots-on-old-class, super-on-old-class, property-on-old-class, old-style-class. Close #1896
-rw-r--r--CONTRIBUTORS.txt2
-rw-r--r--README.rst2
-rw-r--r--pylint/checkers/base.py32
-rw-r--r--pylint/checkers/exceptions.py5
-rw-r--r--pylint/checkers/format.py16
-rw-r--r--pylint/checkers/imports.py32
-rw-r--r--pylint/checkers/newstyle.py57
-rw-r--r--pylint/test/functional/newstyle__slots__.py17
-rw-r--r--pylint/test/functional/newstyle__slots__.txt2
-rw-r--r--pylint/test/input/func_w0233.py1
-rw-r--r--pylint/test/regrtest_data/package/__init__.py5
11 files changed, 31 insertions, 140 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index 199ea8d57..1e4c47745 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -217,3 +217,5 @@ contributors:
* Carey Metcalfe: demoted `try-except-raise` from error to warning
* Marcus Näslund (naslundx): contributor
+
+* Natalie Serebryakova: contributor
diff --git a/README.rst b/README.rst
index 4f58761be..9b222b3cf 100644
--- a/README.rst
+++ b/README.rst
@@ -79,5 +79,3 @@ Pylint is shipped with following additional commands:
* pyreverse: an UML diagram generator
* symilar: an independent similarities checker
* epylint: Emacs and Flymake compatible Pylint
-
-
diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py
index 4f90b1501..889bdbdb0 100644
--- a/pylint/checkers/base.py
+++ b/pylint/checkers/base.py
@@ -1725,37 +1725,6 @@ class PassChecker(_BasicChecker):
(node.parent.doc is not None))):
self.add_message('unnecessary-pass', node=node)
-
-class LambdaForComprehensionChecker(_BasicChecker):
- """check for using a lambda where a comprehension would do.
-
- See <http://www.artima.com/weblogs/viewpost.jsp?thread=98196>
- where GvR says comprehensions would be clearer.
- """
-
- msgs = {'W0110': ('map/filter on lambda could be replaced by comprehension',
- 'deprecated-lambda',
- 'Used when a lambda is the first argument to "map" or '
- '"filter". It could be clearer as a list '
- 'comprehension or generator expression.',
- {'maxversion': (3, 0)}),
- }
-
- @utils.check_messages('deprecated-lambda')
- def visit_call(self, node):
- """visit a Call node, check if map or filter are called with a
- lambda
- """
- if not node.args:
- return
- if not isinstance(node.args[0], astroid.Lambda):
- return
- infered = utils.safe_infer(node.func)
- if (utils.is_builtin_object(infered)
- and infered.name in ['map', 'filter']):
- self.add_message('deprecated-lambda', node=node)
-
-
def _is_one_arg_pos_call(call):
"""Is this a call with exactly 1 argument,
where that argument is positional?
@@ -1954,5 +1923,4 @@ def register(linter):
linter.register_checker(NameChecker(linter))
linter.register_checker(DocStringChecker(linter))
linter.register_checker(PassChecker(linter))
- linter.register_checker(LambdaForComprehensionChecker(linter))
linter.register_checker(ComparisonChecker(linter))
diff --git a/pylint/checkers/exceptions.py b/pylint/checkers/exceptions.py
index 9cbea4f43..b0e07ec3a 100644
--- a/pylint/checkers/exceptions.py
+++ b/pylint/checkers/exceptions.py
@@ -118,11 +118,6 @@ MSGS = {
'operator. This is useless because it raises back the exception '
'immediately. Remove the raise operator or the entire '
'try-except-raise block!'),
- 'W0710': ('Exception doesn\'t inherit from standard "Exception" class',
- 'nonstandard-exception',
- 'Used when a custom exception class is raised but doesn\'t '
- 'inherit from the builtin "Exception" class.',
- {'maxversion': (3, 0)}),
'W0711': ('Exception to catch is the result of a binary "%s" operation',
'binary-op-exception',
'Used when the exception to catch is of the form '
diff --git a/pylint/checkers/format.py b/pylint/checkers/format.py
index 27c3a2fe4..2a03c6176 100644
--- a/pylint/checkers/format.py
+++ b/pylint/checkers/format.py
@@ -91,7 +91,7 @@ MSGS = {
'C0302': ('Too many lines in module (%s/%s)', # was W0302
'too-many-lines',
'Used when a module has too many lines, reducing its readability.'
- ),
+ ),
'C0303': ('Trailing whitespace',
'trailing-whitespace',
'Used when there is whitespace between the end of a line and the '
@@ -131,12 +131,6 @@ MSGS = {
{'old_names': [('C0323', 'no-space-after-operator'),
('C0324', 'no-space-after-comma'),
('C0322', 'no-space-before-operator')]}),
- 'W0332': ('Use of "l" as long integer identifier',
- 'lowercase-l-suffix',
- 'Used when a lower case "l" is used to mark a long integer. You '
- 'should use an upper case "L" since the letter "l" looks too much '
- 'like the digit "1"',
- {'maxversion': (3, 0)}),
'C0327': ('Mixed line endings LF and CRLF',
'mixed-line-endings',
'Used when there are mixed (LF and CRLF) newline signs in a file.'),
@@ -547,7 +541,7 @@ class FormatChecker(BaseTokenChecker):
'choices': ['', 'LF', 'CRLF'],
'help': ('Expected format of line ending, '
'e.g. empty (any line ending), LF or CRLF.')}),
- )
+ )
def __init__(self, linter=None):
BaseTokenChecker.__init__(self, linter)
@@ -906,7 +900,7 @@ class FormatChecker(BaseTokenChecker):
else:
handler(tokens, idx)
- line_num -= 1 # to be ok with "wc -l"
+ line_num -= 1 # to be ok with "wc -l"
if line_num > self.config.max_module_lines:
# Get the line where the too-many-lines (or its message id)
# was disabled or default to 1.
@@ -997,7 +991,7 @@ class FormatChecker(BaseTokenChecker):
if not node.is_statement:
return
if not node.root().pure_python:
- return # XXX block visit of child nodes
+ return # XXX block visit of child nodes
prev_sibl = node.previous_sibling()
if prev_sibl is not None:
prev_line = prev_sibl.fromlineno
@@ -1118,7 +1112,7 @@ class FormatChecker(BaseTokenChecker):
"""return the indent level of the string
"""
indent = self.config.indent_string
- if indent == '\\t': # \t is not interpreted in the configuration file
+ if indent == '\\t': # \t is not interpreted in the configuration file
indent = '\t'
level = 0
unit_size = len(indent)
diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py
index 2aabfc19e..5813db9d2 100644
--- a/pylint/checkers/imports.py
+++ b/pylint/checkers/imports.py
@@ -123,6 +123,7 @@ def _ignore_import_failure(node, modname, ignored_modules):
# utilities to represents import dependencies as tree and dot graph ###########
+
def _make_tree_defs(mod_files_list):
"""get a list of 2-uple (module, list_of_files_which_import_this_module),
it will return a dictionary to represent this as a tree
@@ -303,31 +304,32 @@ class ImportsChecker(BaseChecker):
{'default': DEFAULT_STANDARD_LIBRARY,
'type': 'csv',
'metavar': '<modules>',
- 'help': 'Force import order to recognize a module as part of'
- ' the standard compatibility libraries.'}
- ),
+ 'help': 'Force import order to recognize a module as part of '
+ 'the standard compatibility libraries.'}
+ ),
('known-third-party',
{'default': DEFAULT_KNOWN_THIRD_PARTY,
'type': 'csv',
'metavar': '<modules>',
- 'help': 'Force import order to recognize a module as part of'
- ' a third party library.'}
- ),
+ 'help': 'Force import order to recognize a module as part of '
+ 'a third party library.'}
+ ),
('analyse-fallback-blocks',
{'default': False,
'type': 'yn',
'metavar': '<y_or_n>',
'help': 'Analyse import fallback blocks. This can be used to '
- 'support both Python 2 and 3 compatible code, which means that '
- 'the block might have code that exists only in one or another '
- 'interpreter, leading to false positives when analysed.'},
- ),
+ 'support both Python 2 and 3 compatible code, which '
+ 'means that the block might have code that exists '
+ 'only in one or another interpreter, leading to false '
+ 'positives when analysed.'},
+ ),
('allow-wildcard-with-all',
{'default': False,
'type': 'yn',
'metavar': '<y_or_n>',
'help': 'Allow wildcard imports from modules that define __all__.'}),
- )
+ )
def __init__(self, linter=None):
BaseChecker.__init__(self, linter)
@@ -340,7 +342,7 @@ class ImportsChecker(BaseChecker):
self._report_external_dependencies),
('RP0402', 'Modules dependencies graph',
self._report_dependencies_graph),
- )
+ )
self._site_packages = self._compute_site_packages()
@@ -586,7 +588,7 @@ class ImportsChecker(BaseChecker):
std_imports = []
third_party_imports = []
first_party_imports = []
- # need of a list that holds third or first party ordered import
+ # need of a list that holds third or first party ordered import
external_imports = []
local_imports = []
third_party_not_ignored = []
@@ -671,9 +673,9 @@ class ImportsChecker(BaseChecker):
if not self.linter.is_message_enabled('relative-import'):
return None
if importedmodnode.file is None:
- return False # built-in module
+ return False # built-in module
if modnode is importedmodnode:
- return False # module importing itself
+ return False # module importing itself
if modnode.absolute_import_activated() or getattr(importnode, 'level', None):
return False
if importedmodnode.name != importedasname:
diff --git a/pylint/checkers/newstyle.py b/pylint/checkers/newstyle.py
index 0c3295f4e..cda600d31 100644
--- a/pylint/checkers/newstyle.py
+++ b/pylint/checkers/newstyle.py
@@ -17,7 +17,7 @@ import sys
import astroid
-from pylint.interfaces import IAstroidChecker, INFERENCE, INFERENCE_FAILURE, HIGH
+from pylint.interfaces import IAstroidChecker
from pylint.checkers import BaseChecker
from pylint.checkers.utils import (
check_messages,
@@ -26,14 +26,6 @@ from pylint.checkers.utils import (
)
MSGS = {
- 'E1001': ('Use of __slots__ on an old style class',
- 'slots-on-old-class',
- 'Used when an old style class uses the __slots__ attribute.',
- {'maxversion': (3, 0)}),
- 'E1002': ('Use of super on an old style class',
- 'super-on-old-class',
- 'Used when an old style class uses the super builtin.',
- {'maxversion': (3, 0)}),
'E1003': ('Bad first argument %r given to super()',
'bad-super-call',
'Used when another argument than the current class is given as '
@@ -43,17 +35,6 @@ MSGS = {
'Used when the super builtin didn\'t receive an '
'argument.',
{'maxversion': (3, 0)}),
- 'W1001': ('Use of "property" on an old style class',
- 'property-on-old-class',
- 'Used when Pylint detect the use of the builtin "property" '
- 'on an old style class while this is relying on new style '
- 'classes features.',
- {'maxversion': (3, 0)}),
- 'C1001': ('Old-style class defined.',
- 'old-style-class',
- 'Used when a class is defined that does not inherit from another '
- 'class and does not inherit explicitly from "object".',
- {'maxversion': (3, 0)})
}
@@ -74,39 +55,7 @@ class NewStyleConflictChecker(BaseChecker):
# configuration options
options = ()
- @check_messages('slots-on-old-class', 'old-style-class')
- def visit_classdef(self, node):
- """ Check __slots__ in old style classes and old
- style class definition.
- """
- if '__slots__' in node and not node.newstyle:
- confidence = (INFERENCE if has_known_bases(node)
- else INFERENCE_FAILURE)
- self.add_message('slots-on-old-class', node=node,
- confidence=confidence)
- # The node type could be class, exception, metaclass, or
- # interface. Presumably, the non-class-type nodes would always
- # have an explicit base class anyway.
- if not node.bases and node.type == 'class' and not node.metaclass():
- # We use confidence HIGH here because this message should only ever
- # be emitted for classes at the root of the inheritance hierarchyself.
- self.add_message('old-style-class', node=node, confidence=HIGH)
-
- @check_messages('property-on-old-class')
- def visit_call(self, node):
- """check property usage"""
- parent = node.parent.frame()
- if (isinstance(parent, astroid.ClassDef) and
- not parent.newstyle and
- isinstance(node.func, astroid.Name)):
- confidence = (INFERENCE if has_known_bases(parent)
- else INFERENCE_FAILURE)
- name = node.func.name
- if name == 'property':
- self.add_message('property-on-old-class', node=node,
- confidence=confidence)
-
- @check_messages('super-on-old-class', 'bad-super-call', 'missing-super-argument')
+ @check_messages('bad-super-call', 'missing-super-argument')
def visit_functiondef(self, node):
"""check use of super"""
# ignore actual functions or method within a new style class
@@ -131,7 +80,7 @@ class NewStyleConflictChecker(BaseChecker):
if not klass.newstyle and has_known_bases(klass):
# super should not be used on an old style class
- self.add_message('super-on-old-class', node=node)
+ continue
else:
# super first arg should be the class
if not call.args:
diff --git a/pylint/test/functional/newstyle__slots__.py b/pylint/test/functional/newstyle__slots__.py
deleted file mode 100644
index 0c992e3e7..000000000
--- a/pylint/test/functional/newstyle__slots__.py
+++ /dev/null
@@ -1,17 +0,0 @@
-# pylint: disable=R0903, useless-object-inheritance
-"""test __slots__ on old style class"""
-
-
-class NewStyleClass(object):
- """correct usage"""
- __slots__ = ('a', 'b')
-
-
-class OldStyleClass: # <3.0:[old-style-class,slots-on-old-class]
- """bad usage"""
- __slots__ = ('a', 'b')
-
- def __init__(self):
- pass
-
-__slots__ = 'hop'
diff --git a/pylint/test/functional/newstyle__slots__.txt b/pylint/test/functional/newstyle__slots__.txt
deleted file mode 100644
index 43203906f..000000000
--- a/pylint/test/functional/newstyle__slots__.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-old-style-class:10:OldStyleClass:Old-style class defined.
-slots-on-old-class:10:OldStyleClass:Use of __slots__ on an old style class:INFERENCE
diff --git a/pylint/test/input/func_w0233.py b/pylint/test/input/func_w0233.py
index 5a032d4c2..eb5d97226 100644
--- a/pylint/test/input/func_w0233.py
+++ b/pylint/test/input/func_w0233.py
@@ -1,4 +1,5 @@
# pylint: disable=R0903,W0212,W0403,W0406,no-absolute-import,wrong-import-order, useless-object-inheritance
+
"""test for call to __init__ from a non ancestor class
"""
from __future__ import print_function
diff --git a/pylint/test/regrtest_data/package/__init__.py b/pylint/test/regrtest_data/package/__init__.py
index 26f4c3725..bf6b73cda 100644
--- a/pylint/test/regrtest_data/package/__init__.py
+++ b/pylint/test/regrtest_data/package/__init__.py
@@ -1,4 +1,5 @@
-# pylint: disable=R0903,W0403,useless-object-inheritance
+# pylint: disable=R0903,W0403
+
"""package's __init__ file"""
from . import subpackage
@@ -8,7 +9,7 @@ __revision__ = 0
# E0602 - Undefined variable '__path__'
__path__ += "folder"
-class AudioTime(object):
+class AudioTime:
"""test precedence over the AudioTime submodule"""
DECIMAL = 3