Skip to content

Commit

Permalink
Remove a couple of Python 2 specific checks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Natalie Serebryakova authored and PCManticore committed Aug 15, 2018
1 parent 29cacf3 commit 41d47dd
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 140 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,5 @@ contributors:
* Carey Metcalfe: demoted `try-except-raise` from error to warning

* Marcus Näslund (naslundx): contributor

* Natalie Serebryakova: contributor
2 changes: 0 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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


32 changes: 0 additions & 32 deletions pylint/checkers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1725,37 +1725,6 @@ def visit_pass(self, node):
(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?
Expand Down Expand Up @@ -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))
5 changes: 0 additions & 5 deletions pylint/checkers/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ def _annotated_unpack_infer(stmt, context=None):
'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 '
Expand Down
16 changes: 5 additions & 11 deletions pylint/checkers/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
'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 '
Expand Down Expand Up @@ -131,12 +131,6 @@
{'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.'),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -906,7 +900,7 @@ def process_tokens(self, tokens):
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.
Expand Down Expand Up @@ -997,7 +991,7 @@ def visit_default(self, node):
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
Expand Down Expand Up @@ -1118,7 +1112,7 @@ def check_indent_level(self, string, expected, line_num):
"""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)
Expand Down
32 changes: 17 additions & 15 deletions pylint/checkers/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -340,7 +342,7 @@ def __init__(self, linter=None):
self._report_external_dependencies),
('RP0402', 'Modules dependencies graph',
self._report_dependencies_graph),
)
)

self._site_packages = self._compute_site_packages()

Expand Down Expand Up @@ -586,7 +588,7 @@ def _check_imports_order(self, _module_node):
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 = []
Expand Down Expand Up @@ -671,9 +673,9 @@ def _check_relative_import(self, modnode, importnode, importedmodnode,
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:
Expand Down
57 changes: 3 additions & 54 deletions pylint/checkers/newstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

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,
Expand All @@ -26,14 +26,6 @@
)

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 '
Expand All @@ -43,17 +35,6 @@
'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)})
}


Expand All @@ -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
Expand All @@ -131,7 +80,7 @@ def visit_functiondef(self, node):

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:
Expand Down
17 changes: 0 additions & 17 deletions pylint/test/functional/newstyle__slots__.py

This file was deleted.

2 changes: 0 additions & 2 deletions pylint/test/functional/newstyle__slots__.txt

This file was deleted.

1 change: 1 addition & 0 deletions pylint/test/input/func_w0233.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions pylint/test/regrtest_data/package/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pylint: disable=R0903,W0403,useless-object-inheritance
# pylint: disable=R0903,W0403

"""package's __init__ file"""

from . import subpackage
Expand All @@ -8,7 +9,7 @@
# E0602 - Undefined variable '__path__'
__path__ += "folder"

class AudioTime(object):
class AudioTime:
"""test precedence over the AudioTime submodule"""

DECIMAL = 3

0 comments on commit 41d47dd

Please sign in to comment.