|
204 | 204 | "W8103": ('Translation method _("string") in fields is not necessary.', "translation-field", CHECK_DESCRIPTION), |
205 | 205 | "W8105": ('attribute "%s" deprecated', "attribute-deprecated", CHECK_DESCRIPTION), |
206 | 206 | "W8106": ('Missing `super` call in "%s" method.', "method-required-super", CHECK_DESCRIPTION), |
| 207 | + "W8107": ('Prohibited override of "%s" method.', "prohibited-method-override", CHECK_DESCRIPTION), |
207 | 208 | "W8110": ("Missing `return` (`super` is used) in method %s.", "missing-return", CHECK_DESCRIPTION), |
208 | 209 | "W8111": ( |
209 | 210 | 'Field parameter "%s" is no longer supported. Use "%s" instead.', |
|
303 | 304 | "unlink", |
304 | 305 | "write", |
305 | 306 | ] |
| 307 | +DFTL_PROHIBITED_OVERRIDE_METHODS = [] |
306 | 308 | DFTL_CURSOR_EXPR = [ |
307 | 309 | "cr", # old api |
308 | 310 | "self._cr", # new api |
@@ -495,6 +497,15 @@ class OdooAddons(OdooBaseChecker, BaseChecker): |
495 | 497 | "help": "List of methods where call to `super` is required.separated by a comma.", |
496 | 498 | }, |
497 | 499 | ), |
| 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 | + ), |
498 | 509 | ( |
499 | 510 | "no-missing-return", |
500 | 511 | { |
@@ -1188,7 +1199,9 @@ def check_deprecated_odoo_method(self, node: NodeNG) -> bool: |
1188 | 1199 |
|
1189 | 1200 | return node.name in self._deprecated_odoo_methods |
1190 | 1201 |
|
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 | + ) |
1192 | 1205 | def visit_functiondef(self, node): |
1193 | 1206 | """Check that `api.one` and `api.multi` decorators not exists together |
1194 | 1207 | Check that method `copy` exists `api.one` decorator |
@@ -1216,6 +1229,22 @@ def visit_functiondef(self, node): |
1216 | 1229 | there_is_super = True |
1217 | 1230 | break |
1218 | 1231 |
|
| 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 | + |
1219 | 1248 | there_is_return = any(node.nodes_of_class(nodes.Return, skip_klass=(nodes.FunctionDef, nodes.ClassDef))) |
1220 | 1249 | if ( |
1221 | 1250 | there_is_super |
|
0 commit comments