summaryrefslogtreecommitdiff
path: root/pylint/checkers/stdlib.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2017-07-20 10:33:09 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2017-07-20 10:33:09 +0200
commitef1ac8b286e93cd4a297289fbfdae7b5cf30c12a (patch)
tree172166e326e2c3dcaab06fb1e053e53dd79f4849 /pylint/checkers/stdlib.py
parent0f988582315ba6693e3b840401d86d34f57df77f (diff)
downloadpylint-git-ef1ac8b286e93cd4a297289fbfdae7b5cf30c12a.tar.gz
Added a new warning, 'bad-thread-instantiation'
This message is emitted when the threading.Thread class does not receive the target argument, but receives just one argument, which is by default the group parameter. Close #1327
Diffstat (limited to 'pylint/checkers/stdlib.py')
-rw-r--r--pylint/checkers/stdlib.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/pylint/checkers/stdlib.py b/pylint/checkers/stdlib.py
index 715991eb7..082a63649 100644
--- a/pylint/checkers/stdlib.py
+++ b/pylint/checkers/stdlib.py
@@ -22,6 +22,7 @@ from pylint.checkers import utils
OPEN_FILES = {'open', 'file'}
UNITTEST_CASE = 'unittest.case'
+THREADING_THREAD = 'threading.Thread'
if sys.version_info >= (3, 0):
OPEN_MODULE = '_io'
else:
@@ -99,6 +100,11 @@ class StdlibChecker(BaseChecker):
'The method is marked as deprecated and will be removed in '
'a future version of Python. Consider looking for an '
'alternative in the documentation.'),
+ 'W1506': ('threading.Thread needs the target function',
+ 'bad-thread-instantiation',
+ 'The warning is emitted when a threading.Thread class '
+ 'is instantiated without the target function being passed. '
+ 'By default, the first parameter is the group param, not the target param. '),
}
deprecated = {
@@ -176,8 +182,13 @@ class StdlibChecker(BaseChecker):
},
}
+ def _check_bad_thread_instantiation(self, node):
+ if not node.kwargs and node.args:
+ self.add_message('bad-thread-instantiation', node=node)
+
@utils.check_messages('bad-open-mode', 'redundant-unittest-assert',
- 'deprecated-method')
+ 'deprecated-method',
+ 'bad-thread-instantiation')
def visit_call(self, node):
"""Visit a Call node."""
try:
@@ -187,6 +198,8 @@ class StdlibChecker(BaseChecker):
self._check_open_mode(node)
if inferred.root().name == UNITTEST_CASE:
self._check_redundant_assert(node, inferred)
+ if isinstance(inferred, astroid.ClassDef) and inferred.qname() == THREADING_THREAD:
+ self._check_bad_thread_instantiation(node)
self._check_deprecated_method(node, inferred)
except astroid.InferenceError:
return