Skip to content

Commit bcf9542

Browse files
Merge branch 'OCA:main' into modoolar
2 parents 668bea0 + 5f17158 commit bcf9542

File tree

10 files changed

+185
-112
lines changed

10 files changed

+185
-112
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 9.0.6
2+
current_version = 9.1.2
33
commit = True
44
tag = True
55
sign_tags = True

.github/workflows/test.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,29 @@ on:
88
pull_request:
99
branches:
1010
- main
11+
12+
env:
13+
CACHE_VERSION: 1
14+
PRE_COMMIT_CACHE: ~/.cache/pre-commit
15+
1116
jobs:
1217
test:
1318
runs-on: ${{ matrix.os }}
1419
timeout-minutes: 30
1520
strategy:
1621
fail-fast: false
1722
matrix:
18-
python: ['3.8', '3.9', '3.10', '3.11']
23+
python: ['3.8', '3.9', '3.10', '3.11', '3.12']
1924
os: [ubuntu-latest, windows-latest, macos-latest]
2025
tox_env: [py]
2126
include:
22-
- python: '3.10'
27+
- python: '3.12'
2328
os: ubuntu-latest
2429
tox_env: 'lint'
25-
- python: '3.10'
30+
- python: '3.12'
2631
os: ubuntu-latest
2732
tox_env: 'update-readme'
28-
- python: '3.10'
33+
- python: '3.12'
2934
os: ubuntu-latest
3035
tox_env: 'build'
3136
steps:
@@ -35,14 +40,14 @@ jobs:
3540
git config --global core.autocrlf false
3641
- name: Cache pre-commit packages
3742
id: cache-pre-commit
38-
uses: actions/cache@v3
43+
uses: actions/cache@v4
3944
with:
40-
path: ~/.cache/pre-commit
45+
path: ${{ env.PRE_COMMIT_CACHE }}
4146
key: ${{ runner.os }}-py${{ matrix.python }}-pre-commit
42-
- uses: actions/checkout@v3
47+
- uses: actions/checkout@v4.1.2
4348
with:
4449
fetch-depth: 0
45-
- uses: actions/setup-python@v4
50+
- uses: actions/setup-python@v5.0.0
4651
with:
4752
python-version: ${{ matrix.python }}
4853
architecture: 'x64'
@@ -63,7 +68,7 @@ jobs:
6368
#TODO: Add GITHUB_RUN_ID.GITHUB_RUN_ATTEMPT.GITHUB_RUN_NUMBER to bumpversion to avoid duplicating upload versions or even the git sha
6469
- name: codecov
6570
if: startsWith(matrix.tox_env, 'py') # only coveralls in python tests
66-
uses: codecov/codecov-action@v3
71+
uses: codecov/codecov-action@v4
6772
with:
6873
fail_ci_if_error: false # TODO: Set true after fix token for win&macosx
6974
verbose: true

README.md

Lines changed: 97 additions & 96 deletions
Large diffs are not rendered by default.

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
pylint-plugin-utils==0.7
2-
pylint==3.0.*
3-
validators==0.22.*
1+
pylint-plugin-utils==0.8.*
2+
pylint==3.1.*
3+
validators==0.24.*

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = pylint-odoo
3-
version = 9.0.6
3+
version = 9.1.2
44
author = Odoo Community Association (OCA)
55
author_email = [email protected]
66
summary = Pylint plugin for Odoo
@@ -22,6 +22,7 @@ classifier =
2222
Programming Language :: Python :: 3.9
2323
Programming Language :: Python :: 3.10
2424
Programming Language :: Python :: 3.11
25+
Programming Language :: Python :: 3.12
2526
Topic :: Software Development :: Debuggers
2627
Topic :: Software Development :: Quality Assurance
2728
Topic :: Software Development :: Testing

src/pylint_odoo/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = "9.0.6"
1+
__version__ = "9.1.2"
22

33
from .plugin import register

src/pylint_odoo/checkers/odoo_addons.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
"W8103": ('Translation method _("string") in fields is not necessary.', "translation-field", CHECK_DESCRIPTION),
205205
"W8105": ('attribute "%s" deprecated', "attribute-deprecated", CHECK_DESCRIPTION),
206206
"W8106": ('Missing `super` call in "%s" method.', "method-required-super", CHECK_DESCRIPTION),
207+
"W8107": ('Prohibited override of "%s" method.', "prohibited-method-override", CHECK_DESCRIPTION),
207208
"W8110": ("Missing `return` (`super` is used) in method %s.", "missing-return", CHECK_DESCRIPTION),
208209
"W8111": (
209210
'Field parameter "%s" is no longer supported. Use "%s" instead.',
@@ -303,6 +304,7 @@
303304
"unlink",
304305
"write",
305306
]
307+
DFTL_PROHIBITED_OVERRIDE_METHODS = []
306308
DFTL_CURSOR_EXPR = [
307309
"cr", # old api
308310
"self._cr", # new api
@@ -495,6 +497,15 @@ class OdooAddons(OdooBaseChecker, BaseChecker):
495497
"help": "List of methods where call to `super` is required.separated by a comma.",
496498
},
497499
),
500+
(
501+
"prohibited-method-override",
502+
{
503+
"type": "csv",
504+
"metavar": "<comma separated values>",
505+
"default": DFTL_PROHIBITED_OVERRIDE_METHODS,
506+
"help": "List of methods that have been marked as prohibited to override.",
507+
},
508+
),
498509
(
499510
"no-missing-return",
500511
{
@@ -1188,7 +1199,9 @@ def check_deprecated_odoo_method(self, node: NodeNG) -> bool:
11881199

11891200
return node.name in self._deprecated_odoo_methods
11901201

1191-
@utils.only_required_for_messages("method-required-super", "missing-return", "deprecated-odoo-model-method")
1202+
@utils.only_required_for_messages(
1203+
"method-required-super", "prohibited-method-override", "missing-return", "deprecated-odoo-model-method"
1204+
)
11921205
def visit_functiondef(self, node):
11931206
"""Check that `api.one` and `api.multi` decorators not exists together
11941207
Check that method `copy` exists `api.one` decorator
@@ -1216,6 +1229,22 @@ def visit_functiondef(self, node):
12161229
there_is_super = True
12171230
break
12181231

1232+
# Verify if super attributes are prohibited methods to override
1233+
if there_is_super and self.linter.config.prohibited_method_override or DFTL_PROHIBITED_OVERRIDE_METHODS:
1234+
for attr in node.nodes_of_class(nodes.Attribute):
1235+
if attr.attrname != node.name:
1236+
continue
1237+
func = attr.expr.func
1238+
if (
1239+
isinstance(func, nodes.Name)
1240+
and func.name == "super"
1241+
and (
1242+
attr.attrname in self.linter.config.prohibited_method_override
1243+
or attr.attrname in DFTL_PROHIBITED_OVERRIDE_METHODS
1244+
)
1245+
):
1246+
self.add_message("prohibited-method-override", node=node, args=(attr.attrname,))
1247+
12191248
there_is_return = any(node.nodes_of_class(nodes.Return, skip_klass=(nodes.FunctionDef, nodes.ClassDef)))
12201249
if (
12211250
there_is_super

testing/resources/test_repo/broken_module/tests/test_model.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,25 @@ def method1(self, example_var):
1111
def test_1(self):
1212
self.partner.message_post(body="Test", subtype="mail.mt_comment")
1313
self.partner.message_post("Test", subtype="mail.mt_comment")
14+
15+
def test_base_method_1(self):
16+
# Override prohibited, should fail
17+
super().test_base_method_1()
18+
# No override applied, should not fail
19+
super().test_base_method_2()
20+
return super().test_base_method_3()
21+
22+
def test_base_method_2(self):
23+
# No override applied, should not fail
24+
super(TestModel, self).test_base_method_1()
25+
# Override allowed, should not fail
26+
super(TestModel, self).test_base_method_2()
27+
# No override applied, should not fail
28+
return super(TestModel, self).test_base_method_3()
29+
30+
def test_base_method_3(self):
31+
# No override applied, should not fail
32+
super(TestModel, self).test_base_method_1()
33+
super(TestModel, self).test_base_method_2()
34+
# Override prohibited, should fail
35+
return super(TestModel, self).test_base_method_3()

tests/test_main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,20 @@ def test_option_odoo_deprecated_model_method(self):
410410
pylint_res.linter.stats.by_msg["deprecated-odoo-model-method"],
411411
)
412412

413+
def test_175_prohibited_method_override(self):
414+
"""Test --prohibited_override_methods parameter"""
415+
extra_params = [
416+
"--disable=all",
417+
"--enable=prohibited-method-override",
418+
"--prohibited-method-override=test_base_method_1,test_base_method_3",
419+
]
420+
pylint_res = self.run_pylint(self.paths_modules, extra_params, verbose=True)
421+
real_errors = pylint_res.linter.stats.by_msg
422+
expected_errors = {
423+
"prohibited-method-override": 2,
424+
}
425+
self.assertDictEqual(real_errors, expected_errors)
426+
413427
@staticmethod
414428
def re_replace(sub_start, sub_end, substitution, content):
415429
re_sub = re.compile(rf"^{re.escape(sub_start)}$.*^{re.escape(sub_end)}$", re.M | re.S)

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ envlist =
77
py39,
88
py310,
99
py311,
10+
py312
1011

1112
[testenv]
1213
parallel_show_output=true

0 commit comments

Comments
 (0)