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

Using papyri within IPython fails #330

Closed
melissawm opened this issue Nov 16, 2023 · 1 comment · Fixed by #332
Closed

Using papyri within IPython fails #330

melissawm opened this issue Nov 16, 2023 · 1 comment · Fixed by #332
Labels
bug Something isn't working

Comments

@melissawm
Copy link
Collaborator

Following the Readme instructions for using papyri as an IPython extension, I get the following output:

$ ipython --ext papyri.ipython
Python 3.11.6 | packaged by conda-forge | (main, Oct  3 2023, 10:40:35) [GCC 12.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.17.2 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import numpy as np

In [2]: np.linspace?
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/projects/papyri/papyri/browser.py:248, in guess_load(rough, walk, gen_content, stack, frame)
    247 try:
--> 248     load(candidates[0], walk, rough, gen_content, frame)
    249     return True

File ~/projects/papyri/papyri/browser.py:236, in load(file_path, walk, qa, gen_content, frame)
    235 assert hasattr(blob, "arbitrary")
--> 236 for i in gen_content(blob, frame):
    237     walk.append(i)

File ~/projects/papyri/papyri/browser.py:563, in main.<locals>.gen_content(blob, frame)
    562 doc.append(blank)
--> 563 if blob.signature.value:
    564     doc.append(Text([("signature", blob.signature.value)]))

AttributeError: 'NoneType' object has no attribute 'value'

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
Cell In[2], line 1
----> 1 get_ipython().run_line_magic('pinfo', 'np.linspace')

File ~/micromamba/envs/papyri/lib/python3.11/site-packages/IPython/core/interactiveshell.py:2454, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
   2452     kwargs['local_ns'] = self.get_local_scope(stack_depth)
   2453 with self.builtin_trap:
-> 2454     result = fn(*args, **kwargs)
   2456 # The code below prevents the output from being displayed
   2457 # when using magics with decorator @output_can_be_silenced
   2458 # when the last Python token in the expression is a ';'.
   2459 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File ~/projects/papyri/papyri/ipython.py:34, in Papyri.pinfo(self, parameter_s, namespaces)
     32     if obj is not None:
     33         qa = full_qual(obj)
---> 34         if _ := main(qa):
     35             return
     37 # print 'pinfo par: <%s>' % parameter_s  # dbg
     38 # detail_level: 0 -> obj? , 1 -> obj??

File ~/projects/papyri/papyri/browser.py:631, in main(qualname)
    623 frame = urwid.Frame(urwid.AttrWrap(listbox, "body"))  # , header=header)
    624 frame.footer = urwid.AttrWrap(
    625     urwid.Text(
    626         "q: quit | ?: classic IPython help screen | Arrow/Click: focus links & navigate | enter: follow link"
    627     ),
    628     "header",
    629 )
--> 631 found = guess_load(qualname, walk, gen_content, stack, frame)
    632 if not found:
    633     return False

File ~/projects/papyri/papyri/browser.py:251, in guess_load(rough, walk, gen_content, stack, frame)
    249         return True
    250     except Exception as e:
--> 251         raise ValueError(str(candidates)) from e
    252 return False

ValueError: [PosixPath('/home/melissa/.papyri/ingest/numpy/1.26.0/module/numpy:linspace')]

In [3]: 
@melissawm melissawm added the bug Something isn't working label Nov 16, 2023
@melissawm
Copy link
Collaborator Author

linspace is a bad example - no signature is being collected by gen at all (which I suspect is also a bug?)

However, numpy.loadtxt gets a signature in the json file and results in the same error as above:

  "signature": {
    "kind": "function",
    "parameters": [
      {
        "annotation": {
          "type": "Empty"
        },
        "default": {
          "type": "Empty"
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "name": "fname",
        "type": "ParameterNode"
      },
      {
        "annotation": {
          "type": "Empty"
        },
        "default": {
          "data": "<class 'float'>",
          "type": "str"
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "name": "dtype",
        "type": "ParameterNode"
      },
      {
        "annotation": {
          "type": "Empty"
        },
        "default": {
          "data": "#",
          "type": "str"
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "name": "comments",
        "type": "ParameterNode"
      },
      {
        "annotation": {
          "type": "Empty"
        },
        "default": {
          "data": "None",
          "type": "str"
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "name": "delimiter",
        "type": "ParameterNode"
      },
      {
        "annotation": {
          "type": "Empty"
        },
        "default": {
          "data": "None",
          "type": "str"
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "name": "converters",
        "type": "ParameterNode"
      },
      {
        "annotation": {
          "type": "Empty"
        },
        "default": {
          "data": "0",
          "type": "str"
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "name": "skiprows",
        "type": "ParameterNode"
      },
      {
        "annotation": {
          "type": "Empty"
        },
        "default": {
          "data": "None",
          "type": "str"
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "name": "usecols",
        "type": "ParameterNode"
      },
      {
        "annotation": {
          "type": "Empty"
        },
        "default": {
          "data": "False",
          "type": "str"
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "name": "unpack",
        "type": "ParameterNode"
      },
      {
        "annotation": {
          "type": "Empty"
        },
        "default": {
          "data": "0",
          "type": "str"
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "name": "ndmin",
        "type": "ParameterNode"
      },
      {
        "annotation": {
          "type": "Empty"
        },
        "default": {
          "data": "bytes",
          "type": "str"
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "name": "encoding",
        "type": "ParameterNode"
      },
      {
        "annotation": {
          "type": "Empty"
        },
        "default": {
          "data": "None",
          "type": "str"
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "name": "max_rows",
        "type": "ParameterNode"
      },
      {
        "annotation": {
          "type": "Empty"
        },
        "default": {
          "data": "None",
          "type": "str"
        },
        "kind": "KEYWORD_ONLY",
        "name": "quotechar",
        "type": "ParameterNode"
      },
      {
        "annotation": {
          "type": "Empty"
        },
        "default": {
          "data": "None",
          "type": "str"
        },
        "kind": "KEYWORD_ONLY",
        "name": "like",
        "type": "ParameterNode"
      }
    ],
    "return_annotation": {
      "type": "Empty"
    },
    "type": "SignatureNode"
  },

Carreau added a commit that referenced this issue Nov 20, 2023
Initial proposal for rendering signature in ascii output. Colors can be
debated 😄

This is how it looks like to me:


![Screenshot_20231117_165014](https://github.com/jupyter/papyri/assets/3949932/2ff0b583-c74a-49a0-8006-739e8b3e393b)

And this is how the html rendering already looked like:


![Screenshot_20231117_165434](https://github.com/jupyter/papyri/assets/3949932/2a540a8a-3b22-4694-afd0-49f44b731b70)

Note that default values are not yet rendered, and there may be other
issues to follow up on.

Closes #330
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant