Skip to content

Fix execution contexts on the REPL #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 25, 2020
Merged

Conversation

abadger
Copy link
Contributor

@abadger abadger commented Mar 2, 2019

This is a fix for #422

On the REPL and from the command line, Python doesn't keep source code
in the stack frame for the toplevel. Therefore we can't inspect it and
look for the variable being assigned to in order to remove it from
sys.modules.

This is a cornercase but we can hack around it by trying to retrieve the
variable name from the code object instead. This depends more heavily
on Python internals but this was already code which dove into Python's
internals a bit so perhaps this is okay.

Since I needed to run the tests on Python3.7, this also includes a fix for the test suite on Python3.7 I pulled the Python-3.7 changes out to their own PR.

@abadger abadger force-pushed the fix-422 branch 2 times, most recently from 7f00888 to 5ebf643 Compare March 2, 2019 19:17
@abadger
Copy link
Contributor Author

abadger commented Mar 2, 2019

I'm not sure what the issue is trying to build this on pypy. The test suite passes locally for me on pypy but I have a newer version than is running on travis:

$ pypy --version
Python 2.7.13 (1d8462e42c37, Aug 30 2018, 09:58:57)
[PyPy 6.0.0 with GCC 8.2.1 20180801 (Red Hat 8.2.1-2)]

https://toshio.fedorapeople.org/sh-passing-tests-on-local-pypy.log

@abadger
Copy link
Contributor Author

abadger commented Mar 2, 2019

Okay, I grabbed the travis version of pypy in a VM and I found the problem. Older versions of pypy don't report parent[1] in the same way as CPython (and newer pypy corrects it). I'll special case that to get it to work.

On the REPL and from the command line, Python doesn't keep source code
in the stack frame for the toplevel.  Therefore we can't inspect it and
look for the variable being assigned to in order to remove it from
sys.modules.

This is a cornercase but we can hack around it by trying to retrieve the
variable name from the code object instead.  This depends more heavily
on Python internals but this was already code which dove into Python's
internals a bit so perhaps this is okay.

Fixes amoffat#422
@amoffat amoffat self-assigned this Apr 25, 2020
@amoffat amoffat changed the base branch from master to develop April 25, 2020 11:46
@amoffat amoffat merged commit c1b6141 into amoffat:develop Apr 25, 2020
@amoffat
Copy link
Owner

amoffat commented Apr 25, 2020

Great work on this @abadger and solid test 👍. Will go out with the next release.

@abadger abadger deleted the fix-422 branch April 25, 2020 15:27
@abadger
Copy link
Contributor Author

abadger commented Apr 25, 2020

Cool. Thanks for merging all the outstanding PRs :-)

I noticed some sloppy coding I included in this PR. I'll submit another PR within the hour to address that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants