hy
hy copied to clipboard
Unable to view some docstrings with => (help modulename)
I came across a strange error causing problems viewing the docstring of a module. Below is my setup and a minimum working example.
> python -V
Python 3.11.7
> hy -v
hy 0.28.0+82.g225017d
> uname -a
Linux jupiter 6.1.83_1 #1 SMP PREEMPT_DYNAMIC Thu Mar 28 23:12:50 UTC 2024 x86_64 GNU/Linux
> # also reproduced on a debian bookworm docker image with python 3.11.2 and hy 0.28.0 release
> cat ds.hy
"A test docstring."
(defclass ExampleError [Exception])
> HYSTARTUP="" PAGER=less hy
Hy 0.28.0+82.g225017d using CPython(main) 3.11.7 on Linux
=> (import ds)
=> (help ds)
results in the following error:
Traceback (most recent call last):
File "stdin-851f42906b23b723c670e376d4ab82b6ce401c3d", line 1, in <module>
(help ds)
^^^^^^^^
File "/home/ati/.pyenv/versions/3.11.7/lib/python3.11/pydoc.py", line 2011, in __call__
self.help(request)
File "/home/ati/.pyenv/versions/3.11.7/lib/python3.11/pydoc.py", line 2072, in help
else: doc(request, 'Help on %s:', output=self._output, is_cli=is_cli)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ati/.pyenv/versions/3.11.7/lib/python3.11/pydoc.py", line 1785, in doc
pager(render_doc(thing, title, forceload))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ati/.pyenv/versions/3.11.7/lib/python3.11/pydoc.py", line 1778, in render_doc
return title % desc + '\n\n' + renderer.document(object, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ati/.pyenv/versions/3.11.7/lib/python3.11/pydoc.py", line 479, in document
if inspect.ismodule(object): return self.docmodule(*args)
^^^^^^^^^^^^^^^^^^^^^
File "/home/ati/.pyenv/versions/3.11.7/lib/python3.11/pydoc.py", line 1269, in docmodule
contents.append(self.document(value, key, name))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ati/.pyenv/versions/3.11.7/lib/python3.11/pydoc.py", line 480, in document
if inspect.isclass(object): return self.docclass(*args)
^^^^^^^^^^^^^^^^^^^^
File "/home/ati/.pyenv/versions/3.11.7/lib/python3.11/pydoc.py", line 1331, in docclass
doc = getdoc(object)
^^^^^^^^^^^^^^
File "/home/ati/.pyenv/versions/3.11.7/lib/python3.11/pydoc.py", line 188, in getdoc
result = _getdoc(object) or inspect.getcomments(object)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ati/.pyenv/versions/3.11.7/lib/python3.11/inspect.py", line 1129, in getcomments
lines, lnum = findsource(object)
^^^^^^^^^^^^^^^^^^
File "/home/ati/.pyenv/versions/3.11.7/lib/python3.11/inspect.py", line 1089, in findsource
tree = ast.parse(source)
^^^^^^^^^^^^^^^^^
File "/home/ati/.pyenv/versions/3.11.7/lib/python3.11/ast.py", line 50, in parse
return compile(source, filename, mode, flags,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<unknown>", line 2
(defclass ExampleError [Exception])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
=>
Commenting out the class definition removes the error. Removing the docstring preserves the error.