Skip to content

Commit

Permalink
fix: check base method name on prohibited override
Browse files Browse the repository at this point in the history
  • Loading branch information
Pexers authored Feb 14, 2024
1 parent 8b60511 commit 603a7f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/pylint_odoo/checkers/odoo_addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,8 @@ def visit_functiondef(self, node):
# Verify if super attributes are prohibited methods to override
if there_is_super:
for attr in node.nodes_of_class(nodes.Attribute):
if(attr.attrname != node.name):
continue
func = attr.expr.func
if (
isinstance(func, nodes.Name)
Expand Down
12 changes: 8 additions & 4 deletions testing/resources/test_repo/broken_module/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ def test_1(self):
self.partner.message_post(body="Test", subtype="mail.mt_comment")
self.partner.message_post("Test", subtype="mail.mt_comment")

def test_prohibited_override(self):
def test_base_method_1(self):
# Should fail
super().some_base_method_1(arg_1="Test")
super().test_base_method_1()
# Should not fail
super().some_harmless_method()
return super().test_base_method_2()

def test_base_method_2(self):
# Should not fail
super().test_base_method_1()
# Should fail
return super().some_base_method_2()
return super().test_base_method_2()
6 changes: 3 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@ def test_option_odoo_deprecated_model_method(self):
def test_175_prohibited_method_override(self):
"""Test --prohibited_override_methods parameter"""
extra_params = [
"--disable=all",
"--enable=prohibited-method-override",
"--prohibited-method-override=some_base_method_1,some_base_method_2",
"--disable=all",
"--enable=prohibited-method-override",
"--prohibited-method-override=test_base_method_1,test_base_method_2"
]
pylint_res = self.run_pylint(self.paths_modules, extra_params, verbose=True)
real_errors = pylint_res.linter.stats.by_msg
Expand Down

0 comments on commit 603a7f7

Please sign in to comment.