diff options
author | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2014-12-06 13:41:43 +0200 |
---|---|---|
committer | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2014-12-06 13:41:43 +0200 |
commit | 7c1ebd89b16730b46f2be86d12ac5ab5291b6ee5 (patch) | |
tree | bbda0efdd66a5a7c32f0760c3cb71b955580921b /checkers/stdlib.py | |
parent | 6157a8315ac92d486363411fa57f012ac079d9bb (diff) | |
download | pylint-7c1ebd89b16730b46f2be86d12ac5ab5291b6ee5.tar.gz |
Minimize the except block, by catching only what will raise NoSuchArgumentError.
Diffstat (limited to 'checkers/stdlib.py')
-rw-r--r-- | checkers/stdlib.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/checkers/stdlib.py b/checkers/stdlib.py index 6d4c89c..fadb586 100644 --- a/checkers/stdlib.py +++ b/checkers/stdlib.py @@ -138,15 +138,17 @@ class StdlibChecker(BaseChecker): def _check_open_mode(self, node): """Check that the mode argument of an open or file call is valid.""" try: - mode_arg = utils.get_argument_from_call(node, position=1, keyword='mode') - if mode_arg: - mode_arg = utils.safe_infer(mode_arg) - if (isinstance(mode_arg, astroid.Const) - and not _check_mode_str(mode_arg.value)): - self.add_message('bad-open-mode', node=node, - args=(mode_arg.value)) - except (utils.NoSuchArgumentError, TypeError): - pass + mode_arg = utils.get_argument_from_call(node, position=1, + keyword='mode') + except utils.NoSuchArgumentError: + return + if mode_arg: + mode_arg = utils.safe_infer(mode_arg) + if (isinstance(mode_arg, astroid.Const) + and not _check_mode_str(mode_arg.value)): + self.add_message('bad-open-mode', node=node, + args=mode_arg.value) + def register(linter): """required method to auto register this checker """ |