SeattleTestbed / repy_v2

Seattle Testbed's Repy ("Restricted Python") sandbox, version 2
MIT License
12 stars 50 forks source link

Should RepyV2 ever set `callfunc = "exit"`? #106

Closed aaaaalbert closed 8 years ago

aaaaalbert commented 8 years ago

In RepyV1, the global callfunc variable is set to "initialize" when a program is started, and "exit" after its execution ended. See also the RepyV1 API docs on callfunc. (This allows one to emulate Python's sys.exitfunc, or the atexit module functionality.)

RepyV2 still has callfunc, but it's only ever set to "initialize" as far as I can tell. "exit" isn't ever used; only the dylink lib sets it to "import" when it imports a module. (This can be used to replicate Python's if __name__ == "__main__": idiom.)

I don't know how widely used callfunc != "initialize" ever was, nor why RepyV2 behaves the way it does. I do notice that "exit" was intentionally removed, but the RepyV2 API docs mention it in one place. @JustinCappos, can you perhaps provide additional historical context?

JustinCappos commented 8 years ago

The existing behavior was confusing to many users who wrote print "hello world" or similar and was two lines of output. So, we removed it in RepyV2.

callfunc == 'initialize' lets us have the equivalent of name == "main" so that code can be used as either a library or the main program.

On Wed, Oct 14, 2015 at 8:49 AM, aaaaalbert notifications@github.com wrote:

In RepyV1, the global callfunc variable is set to "initialize" https://github.com/SeattleTestbed/repy_v1/blob/master/repy.py#L204 when a program is started, and "exit" https://github.com/SeattleTestbed/repy_v1/blob/master/repy.py#L237 after its execution ended. See also the RepyV1 API docs on callfunc https://seattle.poly.edu/wiki/RepyApi#callfunc. (This allows one to emulate Python's sys.exitfunc https://docs.python.org/2/library/sys.html#sys.exitfunc, or the atexit module https://docs.python.org/2/library/atexit.html functionality.)

RepyV2 still has callfunc, but it's only ever set to "initialize" as far as I can tell https://github.com/SeattleTestbed/repy_v2/blob/master/repy.py#L129. "exit" isn't ever used; only the dylink lib sets it to "import" https://github.com/SeattleTestbed/seattlelib_v2/blob/master/dylink.r2py#L196 when it imports a module. (This can be used to replicate Python's if name == "main": idiom.)

I don't know how widely used callfunc != "initialize" ever was, nor why RepyV2 behaves the way it does. I do notice that "exit" was intentionally removed https://seattle.poly.edu/changeset/3416/seattle/branches/repy_v2/repy/repy.py, but the RepyV2 API docs mention it in one place https://seattle.poly.edu/wiki/RepyV2API#exitall. @JustinCappos https://github.com/JustinCappos, can you perhaps provide additional historical context?

— Reply to this email directly or view it on GitHub https://github.com/SeattleTestbed/repy_v2/issues/106.

aaaaalbert commented 8 years ago

Thanks!

This means we'll leave things as is: