Skip to content
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

do_inspect lets ipython compute the info twice #51

Closed
jankatins opened this issue Sep 5, 2015 · 2 comments
Closed

do_inspect lets ipython compute the info twice #51

jankatins opened this issue Sep 5, 2015 · 2 comments
Milestone

Comments

@jankatins
Copy link
Contributor

Found this while trying to understand what is needed to make a decorated method get the same signature/completions as the original one, even on py2.7.

From https://github.com/ipython/ipykernel/blob/master/ipykernel/ipkernel.py#L247:

    def do_inspect(self, code, cursor_pos, detail_level=0):
        name = token_at_cursor(code, cursor_pos)
        info = self.shell.object_inspect(name) # computes the complete info
[...]
        if info['found']:
            info_text = self.shell.object_inspect_text(
                name,
                detail_level=detail_level,
            ) # computes it again as a first step
            data['text/plain'] = info_text
[...]

IMO it would be ok to replace the first self.shell.object_inspect(...) with a info = self.shell._object_find(name) and then use if info.found:. The problem is I don't understand what the with self.builtin_trap: in the object_inspect method does (source) and if that's already needed for self.shell._object_find.

@jankatins jankatins changed the title ipykernel inspect lets ipython compute the info twice do_inspect lets ipython compute the info twice Sep 5, 2015
@minrk
Copy link
Member

minrk commented Sep 5, 2015

That makes good sense to me. I just want to avoid calling private APIs in IPython from ipykernel. I think we need to take a pass on oinspect in IPython to make a few more ways to call its pieces.

@jankatins
Copy link
Contributor Author

oinspect probably also needs a pass as inspect.getfullargspec is deprecated ( https://docs.python.org/3/library/inspect.html#inspect.getfullargspec and matplotlib/matplotlib#5014 (comment)) and using the new Signature interface will help with things like getting the proper signature from decorated functions (see matplotlib/matplotlib#4829 (comment) and following comments) updated: getting the call signature from the __wrapped__ func seems to work already on python 3.4.

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

No branches or pull requests

2 participants