diff options
| author | Xavier Morel <xmo@odoo.com> | 2020-10-16 13:59:06 +0000 |
|---|---|---|
| committer | Xavier Morel <xmo@odoo.com> | 2020-11-27 10:00:55 +0000 |
| commit | 3d1c7231a080eebb4f6a7d56cbfa5721bf76befd (patch) | |
| tree | 4954dc532a9753bfea3d3de0c13740fc16ec1949 /odoo | |
| parent | c4a94bc99285aba085badeb1a41e8fe04562ef50 (diff) | |
[ADD] core: 3.9 bytecode instructions in safe_eval
Python 3.9 has 10 new bytecode instructions, for now this commit adds 8
* CONTAINS_OP / IS_OP: moved out of COMPARE_OP which is now only used
for *rich* comparisons (bpo-39156)
* JUMP_IF_NOT_EXC_MATCH: also moved out of COMPARE_OP for the sole
purpose of testing exception types
* RERAISE and WITH_EXCEPT_START (bpo-32949) used to simplify the
context manager bytecode, but RERAISE was then used for
try/except/finally, we don't support context managers in safe_eval
so we don't care about the latter
* LIST_TO_TUPLE, LIST_EXTEND, SET_UPDATE, DICT_MERGE and
DICT_UPDATE (bpo-39320) updates to unpacking (* and **) in various
contexts
* LIST_TO_TUPLE we're skipping as it's only used when calling a
function with two `*arg` parameters (aka `foo(*a, *b)`)
* SET_UPDATE is used for set literals of 3 or more items or
unpacking ({*a})
* LIST_EXTEND is used in the same cases as well as function calls
with unpacking
* DICT_MERGE is used for function calls with `**kwargs`
* DICT_UPDATE is used when unpacking in a dict literal (`{**kw}`)
See odoo/odoo#59980
closes odoo/odoo#62498
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Diffstat (limited to 'odoo')
| -rw-r--r-- | odoo/tools/safe_eval.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/odoo/tools/safe_eval.py b/odoo/tools/safe_eval.py index 83741408eb3..f60bb5e91b6 100644 --- a/odoo/tools/safe_eval.py +++ b/odoo/tools/safe_eval.py @@ -65,6 +65,7 @@ _CONST_OPCODES = set(to_opcodes([ 'BUILD_LIST', 'BUILD_MAP', 'BUILD_TUPLE', 'BUILD_SET', # 3.6: literal map with constant keys https://bugs.python.org/issue27140 'BUILD_CONST_KEY_MAP', + 'LIST_EXTEND', 'SET_UPDATE', ])) - _BLACKLIST # operations which are both binary and inplace, same order as in doc' @@ -82,6 +83,9 @@ _EXPR_OPCODES = _CONST_OPCODES.union(to_opcodes([ # comprehensions 'LIST_APPEND', 'MAP_ADD', 'SET_ADD', 'COMPARE_OP', + # specialised comparisons + 'IS_OP', 'CONTAINS_OP', + 'DICT_MERGE', 'DICT_UPDATE', ])) - _BLACKLIST _SAFE_OPCODES = _EXPR_OPCODES.union(to_opcodes([ @@ -106,6 +110,8 @@ _SAFE_OPCODES = _EXPR_OPCODES.union(to_opcodes([ 'LOAD_FAST', 'STORE_FAST', 'DELETE_FAST', 'UNPACK_SEQUENCE', 'STORE_SUBSCR', 'LOAD_GLOBAL', + + 'RERAISE', 'JUMP_IF_NOT_EXC_MATCH', ])) - _BLACKLIST _logger = logging.getLogger(__name__) |
