[FIX] tools: safe_eval._UNSAFE_ATTRIBUTES as a list

`_UNSAFE_ATTRIBUTES` was changed from a `list` to a `set` in odoo/odoo#151989.
odoo/odoo@cde2781591

Reset it to a `list` as before, by retro-compatibility concerns,
in case developers used features not working on `set`.
For instance:
- `_UNSAFE_ATTRIBUTES.append`
- `_UNSAFE_ATTRIBUTES.extend`
- `_UNSAFE_ATTRIBUTES + ['foo']`

The opportunity is taken to add `_co_code_adaptive`,
which is a new attribute added from Python 3.11,
hence available from Ubuntu Noble.
Firstly added as `_co_quickened` in
https://github.com/python/cpython/commit/001eb520b5757294dc455c900d94b7b153de6cdd
Then renamed to `_co_code_adaptive` in
https://github.com/python/cpython/commit/2bde6827ea4f136297b2d882480b981ff26262b6

The opportunity is also taken to move `mro` out of the `Python 2 functions` section,
as `mro` is available in Python 3, hence making the comment confusing.

Part-of: odoo/odoo#151989
This commit is contained in:
Denis Ledoux
2024-04-11 01:06:51 +02:00
parent 762dce2555
commit aa67ae7879
+6 -5
View File
@@ -50,13 +50,15 @@ for module in _ALLOWED_MODULES:
__import__(module) __import__(module)
_UNSAFE_ATTRIBUTES = { _UNSAFE_ATTRIBUTES = [
# Frames # Frames
'f_builtins', 'f_code', 'f_globals', 'f_locals', 'f_builtins', 'f_code', 'f_globals', 'f_locals',
# Python 2 functions # Python 2 functions
'func_code', 'func_globals', 'mro', 'func_code', 'func_globals',
# Code object # Code object
'co_code', 'co_code', '_co_code_adaptive',
# Method resolution order,
'mro',
# Tracebacks # Tracebacks
'tb_frame', 'tb_frame',
# Generators # Generators
@@ -65,8 +67,7 @@ _UNSAFE_ATTRIBUTES = {
'cr_await', 'cr_code', 'cr_frame', 'cr_await', 'cr_code', 'cr_frame',
# Coroutine generators # Coroutine generators
'ag_await', 'ag_code', 'ag_frame', 'ag_await', 'ag_code', 'ag_frame',
]
}
def to_opcodes(opnames, _opmap=opmap): def to_opcodes(opnames, _opmap=opmap):