From daf67dffb1ee4e1ce7dbb6519ebd178b672e3e44 Mon Sep 17 00:00:00 2001 From: JesusZapata Date: Wed, 18 Jan 2017 18:54:23 +0000 Subject: [PATCH] [ADD] except-pass: Emit message If a except:pass is used fix #252 [FIX] pylint-odoo: Best use of if clause [FIX] pylint-odoo: Validate the body contain only one line [FIX] pylint-odoo: Avoid use \ better use ( [REF] incoherent-interpreter-exec-perm: Better message (#106) [ADD] xml-attribute-translatable: Check XML attribute without translation parameter (#105) Close https://github.com/OCA/pylint-odoo/pull/104 [REF] javascript-lint: Use eslint instead of jshint (#97) [ADD] renamed-field-parameter: Detect deprecated field values (digits_compute, select) (#99) [FIX] Pep8 check and bad index for ODOO_MSGS [ADD] attribute-string-redundant: Check if "string" parameter is equal to variable name (#100) [FIX] attribute-string-redundant: Add "isinstance" validation for nodes Fix https://github.com/OCA/pylint-odoo/issues/109 [IMP] Exclude exception when use as assignation [FIX] Pep8 check local variable 'exception' [FIX] Pep8 blank line at end of file [FIX] Adding more cases of test [REF] Supporting more cases of exception [FIX] Modify file main.py for adding new case of except-pass [IMP] Adding another tests case [FIX] Adding another test case and better validation [FIX] Delete unnecessary condition of if [FIX] Fix comment line --- pylint_odoo/checkers/modules_odoo.py | 15 +++++ pylint_odoo/test/main.py | 1 + .../test_repo/test_module/except_pass.py | 62 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 pylint_odoo/test_repo/test_module/except_pass.py diff --git a/pylint_odoo/checkers/modules_odoo.py b/pylint_odoo/checkers/modules_odoo.py index 6166ee2e..d93eda22 100644 --- a/pylint_odoo/checkers/modules_odoo.py +++ b/pylint_odoo/checkers/modules_odoo.py @@ -117,6 +117,12 @@ 'missing-manifest-dependency', settings.DESC_DFLT ), + 'W%d38' % settings.BASE_OMODULE_ID: ( + 'pass into block except. ' + 'If you really need to use the pass consider logging that exception', + 'except-pass', + settings.DESC_DFLT + ), 'W%d37' % settings.BASE_OMODULE_ID: ( '%s The xml attribute is missing the translation="off" tag %s', 'xml-attribute-translatable', @@ -351,6 +357,15 @@ def visit_import(self, node): if isinstance(node.scope(), astroid.Module): self._check_imported_packages(node, name) + @utils.check_messages('except-pass') + def visit_tryexcept(self, node): + """Visit block try except""" + for handler in node.handlers: + if (not handler.name and + len(handler.body) == 1 and + isinstance(handler.body[0], astroid.node_classes.Pass)): + self.add_message('except-pass', node=handler) + def _check_rst_syntax_error(self): """Check if rst file there is syntax error :return: False if exists errors and diff --git a/pylint_odoo/test/main.py b/pylint_odoo/test/main.py index a6ce4dc4..0cfc543c 100644 --- a/pylint_odoo/test/main.py +++ b/pylint_odoo/test/main.py @@ -58,6 +58,7 @@ 'wrong-tabs-instead-of-spaces': 2, 'eval-referenced': 5, 'xml-syntax-error': 2, + 'except-pass': 3, 'attribute-string-redundant': 33, 'renamed-field-parameter': 2, 'xml-attribute-translatable': 1, diff --git a/pylint_odoo/test_repo/test_module/except_pass.py b/pylint_odoo/test_repo/test_module/except_pass.py new file mode 100644 index 00000000..b259d101 --- /dev/null +++ b/pylint_odoo/test_repo/test_module/except_pass.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +"""Test Except Pass usage""" + + +class TestExceptPass(object): + """Test Except Pass class """ + + def test_method(self): + """Test method """ + try: + raise Exception('Exception') + except Exception: # except-pass + pass + + def test_2_method(self): + """Test 2 method """ + try: + raise Exception('Exception') + except Exception: + pass + print('Exception') + + def test_3_method(self): + """Test 3 method """ + try: + raise Exception('Exception') + except Exception as exception: + pass + if exception: + pass + + def test_4_method(self): + try: + raise Exception('Exception') + except Exception, userError: + pass + if userError: + pass + + def test_5_method(self): + try: + raise Exception('Exception') + except (Exception, IndexError) as exception: + pass + if exception: + pass + + def test_6_method(self): + try: + raise Exception('Exception') + except (Exception, IndexError): # except-pass + pass + + def test_7_method(self): + try: + raise Exception('Exception') + except (Exception, IndexError, NameError), exception: + pass + except Exception: # except-pass + pass + if exception: + pass