Paul Sokolovsky <[email protected]> added the comment:
> I wanted to write a sandbox for Python.
Sandbox indeed, it is.
class NS(dict):
def __setitem__(self, k, v):
if not isinstance(v, type(lambda: 0)):
raise RuntimeError("Global variables considered harmful")
globals = NS()
exec("foo = 1", globals)
But then:
exec("""
global foo
foo = "watch me escaping your sandboxes"
""", globals)
This is due to STORE_GLOBAL not handling dict subclasses, unlike STORE_NAME.
While @Kevin Shweh's issue with LOAD_NAME, and @vstinner's concerns of adding
yet another branch to LOAD_NAME implementation may be one matter, issue with
STORE_GLOBAL is both related and somewhat different. STORE_GLOBAL's should be
relatively infrequent, so adding another branch to it unlikely will be
quantifiable in performance. But lack of its support disallows to write to
tools which police/constrain Python's overdynamicity, which is useful in the
age.
Anyway, I decided to not open a separate ticket for this, but add here. Fairly
speaking, as long as work to support dict subclasses as globals/locals started,
the only reasonable way forward seems to implement it completely.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36220>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com