This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pfalcon
Recipients Kevin Shweh, pfalcon, serhiy.storchaka, vstinner
Date 2019-12-30.16:18:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1577722716.14.0.437059803652.issue36220@roundup.psfhosted.org>
In-reply-to
Content
> 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.
History
Date User Action Args
2019-12-30 16:18:36pfalconsetrecipients: + pfalcon, vstinner, serhiy.storchaka, Kevin Shweh
2019-12-30 16:18:36pfalconsetmessageid: <1577722716.14.0.437059803652.issue36220@roundup.psfhosted.org>
2019-12-30 16:18:36pfalconlinkissue36220 messages
2019-12-30 16:18:35pfalconcreate