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/tools/lru.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/tools/lru.py')
| -rw-r--r-- | odoo/tools/lru.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/odoo/tools/lru.py b/odoo/tools/lru.py index 7c485a039d3..a9e4a8b8f18 100644 --- a/odoo/tools/lru.py +++ b/odoo/tools/lru.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # taken from http://code.activestate.com/recipes/252524-length-limited-o1-lru-cache-implementation/ import threading + +from odoo.tools import pycompat from .func import synchronized __all__ = ['LRU'] @@ -92,6 +94,7 @@ class LRU(object): def __len__(self): return len(self.d) + # FIXME: should this have a P2 and a P3 version or something? @synchronized() def iteritems(self): cur = self.first @@ -106,12 +109,12 @@ class LRU(object): @synchronized() def itervalues(self): - for i,j in self.iteritems(): + for i,j in pycompat.items(self): yield j @synchronized() def keys(self): - return self.d.keys() + return list(pycompat.keys(self.d)) @synchronized() def pop(self,key): |
