Skip to content

Commit 4b9939c

Browse files
committed
[IMP] core: PEP420 native namespace
task-4035335 closes #11914 Related: odoo/odoo#195664 Signed-off-by: Krzysztof Magusiak (krma) <[email protected]>
1 parent ee5a137 commit 4b9939c

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

content/contributing/development/coding_guidelines.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,8 @@ Imports
411411
The imports are ordered as
412412

413413
#. External libraries (one per line sorted and split in python stdlib)
414-
#. Imports of ``odoo``
415-
#. Imports from Odoo modules (rarely, and only if necessary)
414+
#. Imports of ``odoo`` submodules
415+
#. Imports from Odoo addons (rarely, and only if necessary)
416416

417417
Inside these 3 groups, the imported lines are alphabetically sorted.
418418

@@ -424,8 +424,8 @@ Inside these 3 groups, the imported lines are alphabetically sorted.
424424
import time
425425
from datetime import datetime
426426
# 2 : imports of odoo
427-
import odoo
428-
from odoo import api, fields, models, _ # alphabetically ordered
427+
from odoo import api, fields, models # alphabetically ordered
428+
from odoo.fields import Domain
429429
from odoo.tools.safe_eval import safe_eval as eval
430430
# 3 : imports from odoo addons
431431
from odoo.addons.web.controllers.main import login_redirect

content/developer/reference/backend/orm/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Odoo Online version 18.2
1111
`formatted_read_group` as formatted public API. See `#163300 <https://github.com/odoo/odoo/pull/163300>`_.
1212
- `@api.private` is added to distinguish public Python methods from methods exposed for RPC calls.
1313
See `#195402 <https://github.com/odoo/odoo/pull/195402>`_.
14+
- Native namespaces for ``odoo`` module `PEP-420 <https://peps.python.org/pep-0420/>`_.
15+
See `#195664 <https://github.com/odoo/odoo/pull/195664>`_.
1416

1517
Odoo Online version 18.1
1618
========================

extensions/autodoc_field/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from sphinx.domains.python import PyAttribute, PyClasslike
77
from sphinx.ext.autodoc import AttributeDocumenter, ClassDocumenter
88

9-
import odoo
10-
119
nested_parse = RSTState.nested_parse
1210
def patched_nested_parse(self, block, input_offset, node, match_titles=False,
1311
state_machine_class=None, state_machine_kwargs=None):
@@ -23,7 +21,8 @@ class OdooClassDocumenter(ClassDocumenter):
2321

2422
@classmethod
2523
def can_document_member(cls, member, membername, isattr, parent):
26-
return isinstance(member, odoo.models.MetaModel)
24+
from odoo.models import MetaModel
25+
return isinstance(member, MetaModel)
2726

2827
def add_content(self, more_content):
2928
sourcename = self.get_sourcename()
@@ -56,7 +55,8 @@ class FieldDocumenter(AttributeDocumenter):
5655

5756
@classmethod
5857
def can_document_member(cls, member, membername, isattr, parent):
59-
return isinstance(member, odoo.fields.Field)
58+
from odoo.fields import Field
59+
return isinstance(member, Field)
6060

6161
def update_annotations(self, parent):
6262
super().update_annotations(parent)
@@ -67,7 +67,8 @@ def update_annotations(self, parent):
6767
if field.type == 'many2one':
6868
annotation[attrname] = int
6969
elif field.type in ('one2many', 'many2many'):
70-
annotation[attrname] = Sequence[odoo.fields.Command]
70+
from odoo.fields import Command
71+
annotation[attrname] = Sequence[Command]
7172
elif field.type in ('selection', 'reference', 'char', 'text', 'html'):
7273
annotation[attrname] = str
7374
elif field.type == 'boolean':
@@ -104,7 +105,8 @@ def add_content(self, more_content):
104105
if reference:
105106
self.add_line(f":possible_values: `{reference} <{self.config.source_read_replace_vals['GITHUB_PATH']}/{reference}>`__", source_name)
106107
if field.default:
107-
self.add_line(f":default: {field.default(odoo.models.Model)}", source_name)
108+
from odoo.models import Model
109+
self.add_line(f":default: {field.default(Model)}", source_name)
108110

109111
super().add_content(more_content)
110112
if field.help:

extensions/github_link/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ def linkcode_resolve(domain, info):
7171
project = 'upgrade-util'
7272
project_root = os.path.join(os.path.dirname(util.__file__), '../..')
7373
else:
74-
import odoo
74+
from odoo import release
7575
project = 'odoo'
76-
project_root = os.path.join(os.path.dirname(odoo.__file__), '..')
76+
project_root = os.path.join(os.path.dirname(release.__file__), '..')
7777
return make_github_link(
7878
app,
7979
project=project,

0 commit comments

Comments
 (0)