jupyter / papyri

MIT License
82 stars 17 forks source link

Using papyri within IPython fails #330

Closed melissawm closed 7 months ago

melissawm commented 7 months ago

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 commented 7 months ago

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"
  },