Skip to content

Commit

Permalink
Merge pull request #85 from vauxoo-dev/master-oca-super-wo-return-moy
Browse files Browse the repository at this point in the history
[ADD] missing-return
  • Loading branch information
pedrobaeza committed Nov 26, 2016
2 parents af40938 + bb76f82 commit 7b89e5a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pylint_odoo/checkers/no_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
'method-required-super',
settings.DESC_DFLT
),
'W%d10' % settings.BASE_NOMODULE_ID: (
'Missing `return` (`super` is used) in method %s.',
'missing-return',
settings.DESC_DFLT
),
'E%d01' % settings.BASE_NOMODULE_ID: (
'The author key in the manifest file must be a string '
'(with comma separated values)',
Expand Down Expand Up @@ -212,6 +217,9 @@
'MissingError', 'QWebException', 'RedirectWarning', 'UserError',
'ValidationError', 'Warning',
]
DFTL_NO_MISSING_RETURN = [
'__init__', 'setUp', 'tearDown',
]


class NoModuleChecker(BaseChecker):
Expand Down Expand Up @@ -288,6 +296,13 @@ class NoModuleChecker(BaseChecker):
'default': DFTL_VALID_ODOO_VERSIONS,
'help': 'List of valid odoo versions separated by a comma.'
}),
('no_missing_return', {
'type': 'csv',
'metavar': '<comma separated values>',
'default': DFTL_NO_MISSING_RETURN,
'help': 'List of valid missing return method names, '
'separated by a comma.'
}),
)

@utils.check_messages('translation-field', 'invalid-commit',
Expand Down Expand Up @@ -384,6 +399,7 @@ def visit_dict(self, node):
@utils.check_messages('api-one-multi-together',
'copy-wo-api-one', 'api-one-deprecated',
'method-required-super', 'old-api7-method-defined',
'missing-return',
)
def visit_functiondef(self, node):
"""Check that `api.one` and `api.multi` decorators not exists together
Expand Down Expand Up @@ -427,6 +443,22 @@ def visit_functiondef(self, node):
first_args[2] in ['uid', 'user', 'user_id']:
self.add_message('old-api7-method-defined', node=node)

there_is_super = False
for stmt in node.nodes_of_class(astroid.Call):
func = stmt.func
if isinstance(func, astroid.Name) and func.name == 'super':
there_is_super = True
break
there_is_return = False
for stmt in node.nodes_of_class(astroid.Return,
skip_klass=(astroid.FunctionDef,
astroid.ClassDef)):
there_is_return = True
break
if there_is_super and not there_is_return and \
node.name not in self.config.no_missing_return:
self.add_message('missing-return', node=node, args=(node.name))

@utils.check_messages('openerp-exception-warning')
def visit_importfrom(self, node):
if node.modname == 'openerp.exceptions':
Expand Down
1 change: 1 addition & 0 deletions pylint_odoo/test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'missing-manifest-dependency': 2,
'missing-newline-extrafiles': 3,
'missing-readme': 1,
'missing-return': 1,
'no-utf8-coding-comment': 3,
'odoo-addons-relative-import': 4,
'old-api7-method-defined': 2,
Expand Down
7 changes: 7 additions & 0 deletions pylint_odoo/test_repo/broken_module/pylint_oca_broken.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class UseUnusedImport(object):
def method1(self):
return UserError, OtherName, Warning, AE, ValidationError, UserError2

def inherited_method(self):
# Missing return()
super(UseUnusedImport, self).inherited_method()

def write(self):
return super(UseUnusedImport, self).write()


class ApiOne(object):
@api.one
Expand Down

0 comments on commit 7b89e5a

Please sign in to comment.