summaryrefslogtreecommitdiff
path: root/odoo/api.py
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/api.py
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/api.py')
-rw-r--r--odoo/api.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/odoo/api.py b/odoo/api.py
index 1adbd08f6e5..dc51870f20a 100644
--- a/odoo/api.py
+++ b/odoo/api.py
@@ -55,7 +55,7 @@ from weakref import WeakSet
from decorator import decorator
from werkzeug.local import Local, release_local
-from odoo.tools import frozendict, classproperty
+from odoo.tools import frozendict, classproperty, pycompat
_logger = logging.getLogger(__name__)
@@ -85,7 +85,7 @@ class Params(object):
params = []
for arg in self.args:
params.append(repr(arg))
- for item in sorted(self.kwargs.iteritems()):
+ for item in sorted(pycompat.items(self.kwargs)):
params.append("%s=%r" % item)
return ', '.join(params)
@@ -100,7 +100,7 @@ class Meta(type):
# dummy parent class to catch overridden methods decorated with 'returns'
parent = type.__new__(meta, name, bases, {})
- for key, value in attrs.items():
+ for key, value in list(pycompat.items(attrs)):
if not key.startswith('__') and callable(value):
# make the method inherit from decorators
value = propagate(getattr(parent, key, None), value)
@@ -916,7 +916,7 @@ class Environment(Mapping):
def remove_todo(self, field, records):
""" Mark ``field`` as recomputed on ``records``. """
recs_list = [recs - records for recs in self.all.todo.pop(field, [])]
- recs_list = filter(None, recs_list)
+ recs_list = [r for r in recs_list if r]
if recs_list:
self.all.todo[field] = recs_list
@@ -938,15 +938,14 @@ class Environment(Mapping):
# make a full copy of the cache, and invalidate it
cache_dump = dict(
(field, dict(field_cache))
- for field, field_cache in self.cache.iteritems()
+ for field, field_cache in pycompat.items(self.cache)
)
self.invalidate_all()
# re-fetch the records, and compare with their former cache
invalids = []
- for field, field_dump in cache_dump.iteritems():
- ids = filter(None, field_dump)
- records = self[field.model_name].browse(ids)
+ for field, field_dump in pycompat.items(cache_dump):
+ records = self[field.model_name].browse(f for f in field_dump if f)
for record in records:
try:
cached = field_dump[record.id]