[FIX] P3: remove pycompat.{keys,items,values} helpers
Now that we're closer to switching to P3 for good, these helpers have outlived their usefulness, and mostly add noise. All remaining dict.iter*() or dict.view*() must be converted to the normal keys(), values() or items() calls. Whenever the result is likely to be used for more than the scope of a loop, or when the dict needs to be modified during iteration, the calls must be wrapped in a ``list()``, to protect the new P3 semantics. Those cases are very exceptional. Also removed some dead code or improved the API to remove unnecessary conversions.
This commit is contained in:
+4
-9
@@ -233,10 +233,7 @@ methods or functions having been *removed entirely*:
|
||||
.. important::
|
||||
|
||||
When possible, use comprehensions (list, generator, ...) rather than
|
||||
``map`` or ``filter``, otherwise use the cross-version ``pycompat``
|
||||
versions (``pycompat.imap``, ``pycompat.ifilter`` and
|
||||
``pycompat.izip``). The ``pycompat`` versions all return *iterators* and
|
||||
may need to be wrapped in a ``list()`` call to yield a list.
|
||||
``map`` or ``filter``.
|
||||
|
||||
* In Python 3, ``dict.keys``, ``dict.values`` and ``dict.items`` return
|
||||
*views* rather than lists, and the ``iter*`` and ``view*`` methods have
|
||||
@@ -244,11 +241,9 @@ methods or functions having been *removed entirely*:
|
||||
|
||||
.. important::
|
||||
|
||||
Prefer using :func:`odoo.tools.pycompat.keys`,
|
||||
:func:`odoo.tools.pycompat.values` and :func:`odoo.tools.pycompat.items`
|
||||
return cross-version iterators. When needing actual lists (e.g. to
|
||||
modify a dictionary during iteration), wrap one of the calls above in a
|
||||
``list()``.
|
||||
When the result of the above methods is used for more than a one-shot
|
||||
loop (e.g. to be included in returned value), or when the dict needs
|
||||
to be modified during iteration, wrap the calls in a ``list()``.
|
||||
|
||||
builtins
|
||||
--------
|
||||
|
||||
Reference in New Issue
Block a user