You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect behavior on bpython -i module.py and bpython module.py #506
I noticed that the last line there looks just like http://code.activestate.com/recipes/82234-importing-a-dynamically-generated-module/ which has me wondering... Can we use imp to create a new module and set its __dict__ equal to that code.InteractiveInterpreter instance's locals var. Then set sys.modules['__console__'] to that new module.
That would at least provide access to the module that was executed via cli arg. This would still require special casing for any code that expected to find the module at sys.modules['__main__'] but it would work for sys.modules[__name__]
Wow! That's a very literal translation of what I described. I didn't try it because I couldn't figure out where to put the change. Does it actually work? Thanks for doing that for me. Sorry for not submitting a patch myself.
@RichardBronosky, I was writing up the changelog I can't recall what this fixed, and https://bpaste.net/show/5ae7b297bffe has expired. Do you recall what behavior this was fixing? Everything I could think of seems broken once again.
Same here. I looks like it was to do with sys.modules[__name__] being the proper value, which has been fixed in master bpython -- I'm going to say that's what it was: what you fixed was now the namespace of the current module can be found at sys.modules[__name__].
Activity
RichardBronosky commentedon Mar 11, 2015
This is what I've found out so far:
bpython/bpython/cli.py
Line 1907 in 8aa4ddf
bpython/bpython/repl.py
Line 112 in 7eaef53
I noticed that the last line there looks just like http://code.activestate.com/recipes/82234-importing-a-dynamically-generated-module/ which has me wondering... Can we use
impto create a new module and set its__dict__equal to thatcode.InteractiveInterpreterinstance'slocalsvar. Then setsys.modules['__console__']to that new module.That would at least provide access to the module that was executed via cli arg. This would still require special casing for any code that expected to find the module at
sys.modules['__main__']but it would work forsys.modules[__name__]thomasballinger commentedon Mar 13, 2015
I like this approach, you're thinking something like this right? I wonder what the repercussions of swapping out
__main__would be.RichardBronosky commentedon Mar 17, 2015
Wow! That's a very literal translation of what I described. I didn't try it because I couldn't figure out where to put the change. Does it actually work? Thanks for doing that for me. Sorry for not submitting a patch myself.
fixed bug bpython#506
thomasballinger commentedon Apr 27, 2015
I'm going to try this for a day of using -i a lot.
thomasballinger commentedon Dec 6, 2015
@RichardBronosky, I was writing up the changelog I can't recall what this fixed, and https://bpaste.net/show/5ae7b297bffe has expired. Do you recall what behavior this was fixing? Everything I could think of seems broken once again.
RichardBronosky commentedon Dec 9, 2015
I really don't recall. I guess I've learned my lesson about using anything other than gists for documentation.
thomasballinger commentedon Dec 9, 2015
Same here. I looks like it was to do with
sys.modules[__name__]being the proper value, which has been fixed in master bpython -- I'm going to say that's what it was: what you fixed was now the namespace of the current module can be found atsys.modules[__name__].add #506 to changelog