Skip to content

patch inspect.getsource so that I can get the source of interactively defined functions #229

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

Closed
ikanobori opened this issue Jul 4, 2014 · 4 comments · Fixed by #515
Closed

Comments

@ikanobori
Copy link
Contributor

It seems like bpython is already saving a history of everything I type (so that it can be printed on exit); it would be really nifty if 'inspect.getsource' could show me the source of a function so that I could save things out individually.


@thomasballinger
Copy link
Member

Along these lines, I already patch inspect.getsource to get the source of Python builtin functions via https://github.com/punchagan/cinspect in my python startup file. If we're going to use a modified inspect.getsource, might also be cool to check to see if this is installed and use it as well.

@thomasballinger
Copy link
Member

I just looked briefly but I don't understand how IPython is doing this.

@thomasballinger
Copy link
Member

I think we should do this by making our own versions of a few of the methods in inspect.py (the standard library module) so we can pass our history to them.

@thomasballinger
Copy link
Member

Looks like ipython does this by compiling functions with unique filenames for each prompt.

michaelmulley added a commit to michaelmulley/bpython that referenced this issue Mar 25, 2015
- Patches the linecache module to achieve this
- inspect.getsource() works for functions defined on the console
- tracebacks show code for frames inside interactively defined functions
fixes bpython#229
michaelmulley added a commit to michaelmulley/bpython that referenced this issue Mar 25, 2015
- Patches the linecache module to achieve this
- inspect.getsource() works for functions defined on the console
- tracebacks show code for frames inside interactively defined functions
fixes bpython#229
michaelmulley added a commit to michaelmulley/bpython that referenced this issue Mar 25, 2015
- Patches the linecache module to achieve this
- inspect.getsource() works for functions defined on the console
- tracebacks show code for frames inside interactively defined functions
fixes bpython#229
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants