summaryrefslogtreecommitdiff
path: root/checkers
diff options
context:
space:
mode:
authorcpopa <devnull@localhost>2014-07-25 16:10:24 +0200
committercpopa <devnull@localhost>2014-07-25 16:10:24 +0200
commit39c4627f3077bc68e90a9a61530ac06a6aa1c01f (patch)
tree2aaadbfa7e8fac99a77b37ef033938b82f6f56c6 /checkers
parenta288c6eceb47bca013b9c9ebf0c37e3260303654 (diff)
downloadpylint-39c4627f3077bc68e90a9a61530ac06a6aa1c01f.tar.gz
Fix a couple of issues in typecheck.py.
Diffstat (limited to 'checkers')
-rw-r--r--checkers/typecheck.py36
1 files changed, 21 insertions, 15 deletions
diff --git a/checkers/typecheck.py b/checkers/typecheck.py
index efc0909..09caa86 100644
--- a/checkers/typecheck.py
+++ b/checkers/typecheck.py
@@ -18,7 +18,6 @@
import re
import shlex
-import sys
import astroid
from astroid import InferenceError, NotFoundError, YES, Instance
@@ -74,12 +73,13 @@ MSGS = {
'E1125': ('Missing mandatory keyword argument %r in %s call',
'missing-kwoa',
('Used when a function call does not pass a mandatory'
- ' keyword-only argument.'),
+ ' keyword-only argument.'),
{'minversion': (3, 0)}),
'E1126': ('Sequence index is not an int, slice, or instance with __index__',
'invalid-sequence-index',
- 'Used when a sequence type is indexed with an invalid type. Valid \
- types are ints, slices, and objects with an __index__ method.'),
+ 'Used when a sequence type is indexed with an invalid type. '
+ 'Valid types are ints, slices, and objects with an __index__ '
+ 'method.'),
'E1127': ('Slice index is not an int, None, or instance with __index__',
'invalid-slice-index',
'Used when a slice index is not an integer, None, or an object \
@@ -87,7 +87,7 @@ MSGS = {
}
# builtin sequence types in Python 2 and 3.
-sequence_types = set(['str', 'unicode', 'list', 'tuple', 'bytearray',
+SEQUENCE_TYPES = set(['str', 'unicode', 'list', 'tuple', 'bytearray',
'xrange', 'range', 'bytes', 'memoryview'])
def _determine_callable(callable_obj):
@@ -386,7 +386,7 @@ accessed. Python regular expressions are accepted.'}
if isinstance(arg, astroid.Keyword):
keyword = arg.arg
if keyword in keyword_args:
- self.add_message('duplicate-keyword-arg', node=node,
+ self.add_message('duplicate-keyword-arg', node=node,
args=(keyword, 'function'))
keyword_args.add(keyword)
else:
@@ -461,7 +461,8 @@ accessed. Python regular expressions are accepted.'}
break
else:
# Too many positional arguments.
- self.add_message('too-many-function-args', node=node, args=(callable_name,))
+ self.add_message('too-many-function-args',
+ node=node, args=(callable_name,))
break
# 2. Match the keyword arguments.
@@ -470,13 +471,15 @@ accessed. Python regular expressions are accepted.'}
i = parameter_name_to_index[keyword]
if parameters[i][1]:
# Duplicate definition of function parameter.
- self.add_message('redundant-keyword-arg', node=node, args=(keyword, callable_name))
+ self.add_message('redundant-keyword-arg',
+ node=node, args=(keyword, callable_name))
else:
parameters[i][1] = True
elif keyword in kwparams:
if kwparams[keyword][1]: # XXX is that even possible?
# Duplicate definition of function parameter.
- self.add_message('redundant-keyword-arg', node=node, args=(keyword, callable_name))
+ self.add_message('redundant-keyword-arg', node=node,
+ args=(keyword, callable_name))
else:
kwparams[keyword][1] = True
elif called.args.kwarg is not None:
@@ -484,7 +487,8 @@ accessed. Python regular expressions are accepted.'}
pass
else:
# Unexpected keyword argument.
- self.add_message('unexpected-keyword-arg', node=node, args=(keyword, callable_name))
+ self.add_message('unexpected-keyword-arg', node=node,
+ args=(keyword, callable_name))
# 3. Match the *args, if any. Note that Python actually processes
# *args _before_ any keyword arguments, but we wait until after
@@ -521,12 +525,14 @@ accessed. Python regular expressions are accepted.'}
display_name = '<tuple>'
else:
display_name = repr(name)
- self.add_message('no-value-for-parameter', node=node, args=(display_name, callable_name))
+ self.add_message('no-value-for-parameter', node=node,
+ args=(display_name, callable_name))
for name in kwparams:
defval, assigned = kwparams[name]
if defval is None and not assigned:
- self.add_message('missing-kwoa', node=node, args=(name, callable_name))
+ self.add_message('missing-kwoa', node=node,
+ args=(name, callable_name))
@check_messages('invalid-sequence-index')
def visit_extslice(self, node):
@@ -544,7 +550,7 @@ accessed. Python regular expressions are accepted.'}
# slice or instances with __index__.
parent_type = safe_infer(node.parent.value)
-
+
if not isinstance(parent_type, (astroid.Class, astroid.Instance)):
return
@@ -580,7 +586,7 @@ accessed. Python regular expressions are accepted.'}
if not itemmethod.parent:
return
- if itemmethod.parent.name not in sequence_types:
+ if itemmethod.parent.name not in SEQUENCE_TYPES:
return
# For ExtSlice objects coming from visit_extslice, no further
@@ -634,7 +640,7 @@ accessed. Python regular expressions are accepted.'}
if index_type.pytype() in (BUILTINS + '.int',
BUILTINS + '.NoneType'):
continue
-
+
try:
index_type.getattr('__index__')
return