Skip to content

do_inspect lets ipython compute the info twice #51

Closed
@jankatins

Description

@jankatins

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions