summaryrefslogtreecommitdiff
path: root/checkers
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2013-07-17 15:15:20 +0300
committerClaudiu Popa <pcmanticore@gmail.com>2013-07-17 15:15:20 +0300
commit1230a00806d6a9c0d91a32b719a0417e300554ea (patch)
tree83116552d68d60a5a9a5e6acdd9b317865526162 /checkers
parent246757e9f37266c95e9a51b478673c473f6afa2c (diff)
parent0390e2ea086f9e8d9e2286ff1402ec1661d402e4 (diff)
downloadpylint-1230a00806d6a9c0d91a32b719a0417e300554ea.tar.gz
Merged logilab/pylint into default
Diffstat (limited to 'checkers')
-rw-r--r--checkers/base.py13
-rw-r--r--checkers/exceptions.py3
-rw-r--r--checkers/format.py16
-rw-r--r--checkers/misc.py3
-rw-r--r--checkers/stdlib.py15
-rw-r--r--checkers/typecheck.py3
6 files changed, 37 insertions, 16 deletions
diff --git a/checkers/base.py b/checkers/base.py
index 4d05c0e..b7dce70 100644
--- a/checkers/base.py
+++ b/checkers/base.py
@@ -16,7 +16,7 @@
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""basic checker for Python code"""
-
+import sys
import astroid
from logilab.common.ureports import Table
from astroid import are_exclusive
@@ -377,7 +377,8 @@ functions, methods
'W0122': ('Use of the exec statement',
'exec-statement',
'Used when you use the "exec" statement, to discourage its \
- usage. That doesn\'t mean you can not use it !'),
+ usage. That doesn\'t mean you can not use it !',
+ {'maxversion': (3, 0)}),
'W0141': ('Used builtin function %r',
'bad-builtin',
@@ -404,7 +405,8 @@ functions, methods
'W0121': ('Use raise ErrorClass(args) instead of raise ErrorClass, args.',
'old-raise-syntax',
"Used when the alternate raise syntax 'raise foo, bar' is used "
- "instead of 'raise foo(bar)'."),
+ "instead of 'raise foo(bar)'.",
+ {'maxversion': (3, 0)}),
'C0121': ('Missing required attribute "%s"', # W0103
'missing-module-attribute',
@@ -588,6 +590,8 @@ functions, methods
code)
"""
self._check_unreachable(node)
+ if sys.version_info >= (3, 0):
+ return
if node.exc is not None and node.inst is not None and node.tback is None:
self.add_message('old-raise-syntax', node=node)
@@ -954,7 +958,8 @@ class LambdaForComprehensionChecker(_BasicChecker):
'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.'),
+ 'comprehension or generator expression.',
+ {'maxversion': (3, 0)}),
}
@check_messages('deprecated-lambda')
diff --git a/checkers/exceptions.py b/checkers/exceptions.py
index 1e1be2a..00b1e44 100644
--- a/checkers/exceptions.py
+++ b/checkers/exceptions.py
@@ -75,7 +75,8 @@ MSGS = {
'unpacking-in-except',
'Python3 will not allow implicit unpacking of exceptions in except '
'clauses. '
- 'See http://www.python.org/dev/peps/pep-3110/'),
+ 'See http://www.python.org/dev/peps/pep-3110/',
+ {'maxversion': (3, 0)}),
}
diff --git a/checkers/format.py b/checkers/format.py
index 8fa1dc6..0874272 100644
--- a/checkers/format.py
+++ b/checkers/format.py
@@ -46,6 +46,9 @@ MSGS = {
'trailing-whitespace',
'Used when there is whitespace between the end of a line and the '
'newline.'),
+ 'C0304': ('Final newline missing',
+ 'missing-final-newline',
+ 'Used when the last line in a file is missing a newline.'),
'W0311': ('Bad indentation. Found %s %s, expected %s',
'bad-indentation',
'Used when an unexpected number of indentation\'s tabulations or '
@@ -337,11 +340,14 @@ class FormatChecker(BaseTokenChecker):
ignore_long_line = self.config.ignore_long_lines
for line in lines.splitlines(True):
- stripped_line = line.rstrip()
- if line != stripped_line + '\n':
- self.add_message('C0303', line=i)
- # Don't count excess whitespace in the line length.
- line = stripped_line
+ if not line.endswith('\n'):
+ self.add_message('C0304', line=i)
+ else:
+ stripped_line = line.rstrip()
+ if line != stripped_line + '\n':
+ self.add_message('C0303', line=i)
+ # Don't count excess whitespace in the line length.
+ line = stripped_line
mobj = OPTION_RGX.search(line)
if mobj and mobj.group(1).split('=', 1)[0].strip() == 'disable':
line = line.split('#')[0].rstrip()
diff --git a/checkers/misc.py b/checkers/misc.py
index 9d7572e..11c43a9 100644
--- a/checkers/misc.py
+++ b/checkers/misc.py
@@ -30,7 +30,8 @@ MSGS = {
'W0512': ('Cannot decode using encoding "%s", unexpected byte at position %d',
'invalid-encoded-data',
'Used when a source line cannot be decoded using the specified '
- 'source file encoding.'),
+ 'source file encoding.',
+ {'maxversion': (3, 0)}),
}
diff --git a/checkers/stdlib.py b/checkers/stdlib.py
index 364633b..89261eb 100644
--- a/checkers/stdlib.py
+++ b/checkers/stdlib.py
@@ -16,6 +16,7 @@
"""Checkers for various standard library functions."""
import re
+import sys
import astroid
@@ -25,6 +26,10 @@ from pylint.checkers import utils
_VALID_OPEN_MODE_REGEX = r'^(r?U|[rwa]\+?b?)$'
+if sys.version_info >= (3, 0):
+ OPEN_MODULE = '_io'
+else:
+ OPEN_MODULE = '__builtin__'
class OpenModeChecker(BaseChecker):
__implements__ = (IAstroidChecker,)
@@ -36,13 +41,15 @@ class OpenModeChecker(BaseChecker):
'Python supports: r, w, a modes with b, +, and U options. '
'See http://docs.python.org/2/library/functions.html#open'),
}
-
+
@utils.check_messages('W1501')
def visit_callfunc(self, node):
"""Visit a CallFunc node."""
- if (hasattr(node, 'func') and utils.is_builtin_object(utils.safe_infer(node.func))):
- if getattr(node.func, 'name', None) in ('open', 'file'):
- self._check_open_mode(node)
+ if hasattr(node, 'func'):
+ infer = utils.safe_infer(node.func)
+ if infer and infer.root().name == OPEN_MODULE:
+ if getattr(node.func, 'name', None) in ('open', 'file'):
+ self._check_open_mode(node)
def _check_open_mode(self, node):
"""Check that the mode argument of an open or file call is valid."""
diff --git a/checkers/typecheck.py b/checkers/typecheck.py
index 4783d22..2c78459 100644
--- a/checkers/typecheck.py
+++ b/checkers/typecheck.py
@@ -58,7 +58,8 @@ MSGS = {
'E1122': ('Duplicate keyword argument %r in function call',
'duplicate-keyword-arg',
'Used when a function call passes the same keyword argument \
- multiple times.'),
+ multiple times.',
+ {'maxversion': (2, 6)}),
'E1123': ('Passing unexpected keyword argument %r in function call',
'unexpected-keyword-arg',
'Used when a function call passes a keyword argument that \