summaryrefslogtreecommitdiff
path: root/odoo/addons/base/module
diff options
context:
space:
mode:
authorxmo-odoo <xmo@odoo.com>2017-05-10 09:39:55 +0200
committerGitHub <noreply@github.com>2017-05-10 09:39:55 +0200
commitfffaf735f58f1ac57781c095eb552de6d1fcdc47 (patch)
tree88ab0ab65430d871862a836524e0ecc890d1674d /odoo/addons/base/module
parent10eee18a047d35305dc46282e610e88936d81ffc (diff)
[FIX] P3: list -> iterable builtins (#16811)
In Python 3: * various builtins and dict methods were changed to return view/iterable objects rather than lists * and the separate Python 2 view/iterable builtins and methods were removed altogether This is problematic when using these items as list (which the happens repeatedly in Odoo), but more viciously when iterating *multiple times* over them (which also happens, which I've messed up multiple times while writing this, and which is a pain to debug even when you've just created the issue). Convert all code using these to semantics-matching cross-version helper functions to get the LCD behaviour between P2 and P3, and forbid the builtins via lint. issue #8530
Diffstat (limited to 'odoo/addons/base/module')
-rw-r--r--odoo/addons/base/module/module.py16
-rw-r--r--odoo/addons/base/module/report/ir_module_reference_print.py4
2 files changed, 12 insertions, 8 deletions
diff --git a/odoo/addons/base/module/module.py b/odoo/addons/base/module/module.py
index ae36ccd1727..c8a83a01bf1 100644
--- a/odoo/addons/base/module/module.py
+++ b/odoo/addons/base/module/module.py
@@ -10,6 +10,8 @@ import shutil
import tempfile
import zipfile
+from odoo.tools import pycompat
+
try:
from urllib import parse as urlparse
from urllib.request import urlopen
@@ -209,9 +211,9 @@ class Module(models.Model):
def format_view(v):
return '%s%s (%s)' % (v.inherit_id and '* INHERIT ' or '', v.name, v.type)
- module.views_by_module = "\n".join(sorted(map(format_view, browse('ir.ui.view'))))
- module.reports_by_module = "\n".join(sorted(map(attrgetter('name'), browse('ir.actions.report'))))
- module.menus_by_module = "\n".join(sorted(map(attrgetter('complete_name'), browse('ir.ui.menu'))))
+ module.views_by_module = "\n".join(sorted(format_view(v) for v in browse('ir.ui.view')))
+ module.reports_by_module = "\n".join(sorted(r.name for r in browse('ir.actions.report')))
+ module.menus_by_module = "\n".join(sorted(m.complete_name for m in browse('ir.ui.menu')))
@api.depends('icon')
def _get_icon_image(self):
@@ -668,7 +670,7 @@ class Module(models.Model):
_logger.debug('Install from url: %r', urls)
try:
# 1. Download & unzip missing modules
- for module_name, url in urls.iteritems():
+ for module_name, url in pycompat.items(urls):
if not url:
continue # nothing to download, local version is already the last one
@@ -687,7 +689,7 @@ class Module(models.Model):
assert os.path.isdir(os.path.join(tmp, module_name))
# 2a. Copy/Replace module source in addons path
- for module_name, url in urls.iteritems():
+ for module_name, url in pycompat.items(urls):
if module_name == OPENERP or not url:
continue # OPENERP is special case, handled below, and no URL means local module
module_path = modules.get_module_path(module_name, downloaded=True, display_warning=False)
@@ -719,11 +721,11 @@ class Module(models.Model):
self.update_list()
- with_urls = [module_name for module_name, url in urls.iteritems() if url]
+ with_urls = [module_name for module_name, url in pycompat.items(urls) if url]
downloaded = self.search([('name', 'in', with_urls)])
installed = self.search([('id', 'in', downloaded.ids), ('state', '=', 'installed')])
- to_install = self.search([('name', 'in', urls.keys()), ('state', '=', 'uninstalled')])
+ to_install = self.search([('name', 'in', list(urls)), ('state', '=', 'uninstalled')])
post_install_action = to_install.button_immediate_install()
if installed or to_install:
diff --git a/odoo/addons/base/module/report/ir_module_reference_print.py b/odoo/addons/base/module/report/ir_module_reference_print.py
index 1f2dff53243..a933cdd9430 100644
--- a/odoo/addons/base/module/report/ir_module_reference_print.py
+++ b/odoo/addons/base/module/report/ir_module_reference_print.py
@@ -2,6 +2,8 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models
+from odoo.tools import pycompat
+
class IrModelReferenceReport(models.AbstractModel):
_name = 'report.base.report_irmodulereference'
@@ -21,7 +23,7 @@ class IrModelReferenceReport(models.AbstractModel):
if data:
res_ids = data.mapped('res_id')
fnames = self.env['ir.model.fields'].browse(res_ids).mapped('name')
- return sorted(self.env[model].fields_get(fnames).iteritems())
+ return sorted(pycompat.items(self.env[model].fields_get(fnames)))
return []
@api.model