Message359046
> 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. |
|
Date |
User |
Action |
Args |
2019-12-30 16:18:36 | pfalcon | set | recipients:
+ pfalcon, vstinner, serhiy.storchaka, Kevin Shweh |
2019-12-30 16:18:36 | pfalcon | set | messageid: <1577722716.14.0.437059803652.issue36220@roundup.psfhosted.org> |
2019-12-30 16:18:36 | pfalcon | link | issue36220 messages |
2019-12-30 16:18:35 | pfalcon | create | |
|