pdoc3 / pdoc3/pdoc

Exception when a type hint is a torch.tensor

Open
#342 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.2k
Forks
146
PR merge metrics
No merged PRs in 30d

Description

Take the following script saved in bug.py:

import torch

def no_likey(input: torch.tensor):
    pass

Now execute pdoc --html bug.py. An exception is raised:

Traceback (most recent call last):
  File "c:\myproject\venv\lib\site-packages\pdoc\__init__.py", line 158, in _render_template
    return t.render(**config).strip()
  File "c:\myproject\venv\lib\site-packages\mako\template.py", line 473, in render
    return runtime._render(self, self.callable_, args, data)
  File "c:\myproject\venv\lib\site-packages\mako\runtime.py", line 878, in _render
    _render_context(
  File "c:\myproject\venv\lib\site-packages\mako\runtime.py", line 920, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "c:\myproject\venv\lib\site-packages\mako\runtime.py", line 947, in _exec_template
    callable_(context, *args, **kwargs)
  File "c:/myproject/venv/lib/site-packages/pdoc/templates/html.mako", line 429, in render_body
    ${show_module(module)}
  File "c:/myproject/venv/lib/site-packages/pdoc/templates/html.mako", line 0, in show_module

  File "c:/myproject/venv/lib/site-packages/pdoc/templates/html.mako", line 168, in render_show_module
    ${show_func(f)}
  File "c:/myproject/venv/lib/site-packages/pdoc/templates/html.mako", line 109, in show_func
    params = ', '.join(f.params(annotate=show_type_annotations, link=link))
  File "c:\myproject\venv\lib\site-packages\pdoc\__init__.py", line 1340, in params
    return self._params(self, annotate=annotate, link=link, module=self.module)
  File "c:\myproject\venv\lib\site-packages\pdoc\__init__.py", line 1424, in _params
    annotation = _formatannotation(p.annotation).replace(' ', '\N{NBSP}')
  File "c:\myproject\venv\lib\site-packages\pdoc\__init__.py", line 1215, in _formatannotation
    if module.startswith('nptyping'):  # GH-231
AttributeError: 'NoneType' object has no attribute 'startswith'

Traceback (most recent call last):
  File "c:\program files\python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\program files\python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "c:\myproject\venv\Scripts\pdoc3.exe\__main__.py", line 7, in <module>
  File "c:\myproject\venv\lib\site-packages\pdoc\cli.py", line 572, in main
    recursive_write_files(module, ext='.html', **template_config)
  File "c:\myproject\venv\lib\site-packages\pdoc\cli.py", line 344, in recursive_write_files
    f.write(m.html(**kwargs))
  File "c:\myproject\venv\lib\site-packages\pdoc\__init__.py", line 832, in html
    html = _render_template('/html.mako', module=self, **kwargs)
  File "c:\myproject\venv\lib\site-packages\pdoc\__init__.py", line 158, in _render_template
    return t.render(**config).strip()
  File "c:\myproject\venv\lib\site-packages\mako\template.py", line 473, in render
    return runtime._render(self, self.callable_, args, data)
  File "c:\myproject\venv\lib\site-packages\mako\runtime.py", line 878, in _render
    _render_context(
  File "c:\myproject\venv\lib\site-packages\mako\runtime.py", line 920, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "c:\myproject\venv\lib\site-packages\mako\runtime.py", line 947, in _exec_template
    callable_(context, *args, **kwargs)
  File "_html_mako", line 143, in render_body
  File "_html_mako", line 44, in show_module
  File "_html_mako", line 414, in render_show_module
  File "_html_mako", line 329, in show_func
  File "c:\myproject\venv\lib\site-packages\pdoc\__init__.py", line 1340, in params
    return self._params(self, annotate=annotate, link=link, module=self.module)
  File "c:\myproject\venv\lib\site-packages\pdoc\__init__.py", line 1424, in _params
    annotation = _formatannotation(p.annotation).replace(' ', '\N{NBSP}')
  File "c:\myproject\venv\lib\site-packages\pdoc\__init__.py", line 1215, in _formatannotation
    if module.startswith('nptyping'):  # GH-231
AttributeError: 'NoneType' object has no attribute 'startswith'
Additional info

pdoc3==0.9.2
Python 3.8.10
Windows 10

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the issue's bug.py example by running pdoc --html bug.py. Start in pdoc/__init__.py at _formatannotation, where the traceback shows the failure, and verify that generation completes and renders the torch.tensor annotation without an exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
documentation
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.