Skip to content

odoo-addons-relative-import (ODOO023)

Preview (since 0.16.2.2) · Related issues · View source

Derived from the odoo linter.

This rule is unstable and in preview. The --preview flag is required for use.

What it does

Checks for odoo.addons.<this_module> imports, absolute imports of the very module the file itself belongs to.

Why is this bad?

A module importing itself by its own name (instead of using a relative import) breaks if the module is ever renamed or vendored under a different name.

Example

# in my_module/models/foo.py
from odoo.addons.my_module import models

Use instead:

from . import models