From ef1ac8b286e93cd4a297289fbfdae7b5cf30c12a Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Thu, 20 Jul 2017 10:33:09 +0200 Subject: 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 --- pylint/checkers/stdlib.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'pylint/checkers/stdlib.py') 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 -- cgit v1.2.1