diff options
| author | xmo-odoo <xmo@odoo.com> | 2017-05-10 09:39:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-10 09:39:55 +0200 |
| commit | fffaf735f58f1ac57781c095eb552de6d1fcdc47 (patch) | |
| tree | 88ab0ab65430d871862a836524e0ecc890d1674d /odoo/modules/graph.py | |
| parent | 10eee18a047d35305dc46282e610e88936d81ffc (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/modules/graph.py')
| -rw-r--r-- | odoo/modules/graph.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/odoo/modules/graph.py b/odoo/modules/graph.py index d962ea78bdc..731b6f6557a 100644 --- a/odoo/modules/graph.py +++ b/odoo/modules/graph.py @@ -8,7 +8,7 @@ import logging import odoo import odoo.tools as tools - +from odoo.tools import pycompat _logger = logging.getLogger(__name__) @@ -36,7 +36,7 @@ class Graph(dict): return # update the graph with values from the database (if exist) ## First, we set the default values for each package in graph - additional_data = dict((key, {'id': 0, 'state': 'uninstalled', 'dbdemo': False, 'installed_version': None}) for key in self.keys()) + additional_data = {key: {'id': 0, 'state': 'uninstalled', 'dbdemo': False, 'installed_version': None} for key in pycompat.keys(self)} ## Then we get the values from the database cr.execute('SELECT name, id, state, demo AS dbdemo, latest_version AS installed_version' ' FROM ir_module_module' @@ -46,8 +46,8 @@ class Graph(dict): ## and we update the default values with values from the database additional_data.update((x['name'], x) for x in cr.dictfetchall()) - for package in self.values(): - for k, v in additional_data[package.name].items(): + for package in pycompat.values(self): + for k, v in pycompat.items(additional_data[package.name]): setattr(package, k, v) def add_module(self, cr, module, force=None): @@ -94,7 +94,7 @@ class Graph(dict): self.update_from_db(cr) for package in later: - unmet_deps = filter(lambda p: p not in self, dependencies[package]) + unmet_deps = [p for p in dependencies[package] if p not in self] _logger.error('module %s: Unmet dependencies: %s', package, ', '.join(unmet_deps)) return len(self) - len_graph @@ -102,9 +102,9 @@ class Graph(dict): def __iter__(self): level = 0 - done = set(self.keys()) + done = set(pycompat.keys(self)) while done: - level_modules = sorted((name, module) for name, module in self.items() if module.depth==level) + level_modules = sorted((name, module) for name, module in pycompat.items(self) if module.depth==level) for name, module in level_modules: done.remove(name) yield module @@ -164,7 +164,10 @@ class Node(object): setattr(child, name, value + 1) def __iter__(self): - return itertools.chain(iter(self.children), *map(iter, self.children)) + return itertools.chain( + self.children, + itertools.chain.from_iterable(self.children) + ) def __str__(self): return self._pprint() |
