Skip to content

Exception when a type hint is a torch.tensor #342

Open
@bot-me-not

Description

@bot-me-not

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions