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

Error importing module: no signature found for builtin type <class 'type I wrote'> #678

Open
JesseTG opened this issue Apr 10, 2024 · 3 comments
Labels

Comments

@JesseTG
Copy link

JesseTG commented Apr 10, 2024

Problem Description

When attempting to use pdoc on my package, I get a stack trace similar to the following when trying to view the doc page for any module:

Traceback (most recent call last):
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/pdoc/web.py", line 82, in handle_request
    out = render.html_module(
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/pdoc/render.py", line 106, in html_module
    return env.get_template("module.html.jinja2").render(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/pdoc/templates/default/module.html.jinja2", line 311, in top-level template code
    {%- if loop.nextitem -%}
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/pdoc/templates/default/frame.html.jinja2", line 36, in top-level template code
    {% block body %}
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/pdoc/templates/default/frame.html.jinja2", line 42, in block 'body'
    {% block content %}{% endblock %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/pdoc/templates/default/module.html.jinja2", line 101, in block 'content'
    {% block module_contents %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/pdoc/templates/default/module.html.jinja2", line 108, in block 'module_contents'
    {{ member(m) }}
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/jinja2/runtime.py", line 777, in _invoke
    rv = self._func(*arguments)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/pdoc/templates/default/module.html.jinja2", line 198, in template
    {{ function(doc) }}
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/jinja2/runtime.py", line 777, in _invoke
    rv = self._func(*arguments)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/pdoc/templates/default/module.html.jinja2", line 176, in template
    {{- fn.signature | format_signature(colon=True) | linkify }}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/pdoc/render_helpers.py", line 358, in linkify
    re.sub(
  File "/usr/lib/python3.12/re/__init__.py", line 186, in sub
    return _compile(pattern, flags).sub(repl, string, count)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/pdoc/render_helpers.py", line 343, in linkify_repl
    doc is not None and context["is_public"](doc).strip()
                        ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/jinja2/runtime.py", line 777, in _invoke
    rv = self._func(*arguments)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/pdoc/templates/default/module.html.jinja2", line 242, in template
    {% if "@private" in doc.docstring %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/jinja2/environment.py", line 485, in getattr
    return getattr(obj, attribute)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/functools.py", line 995, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "/home/jesse/.virtualenvs/libretro.py/lib/python3.12/site-packages/pdoc/doc.py", line 594, in docstring
    + str(inspect.signature(self.obj)).replace(" -> None", "")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/inspect.py", line 3327, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/inspect.py", line 3071, in from_callable
    return _signature_from_callable(obj, sigcls=cls,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/inspect.py", line 2633, in _signature_from_callable
    raise ValueError(
ValueError: no signature found for builtin type <class 'libretro.api.content.retro_system_info'>

Steps to reproduce the behavior:

  1. On Windows or Linux, clone this repository.
  2. cd to the cloned repo.
  3. Run pdoc src/libretro.
  4. Go to the hosted doc site.
  5. Select any module.
  6. You will see the above stack trace (or something similar).

System Information

pdoc: 14.4.0
Python: 3.12.2
Platform: Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.35

Additionally:

pdoc: 14.4.0
Python: 3.12.2
Platform: Windows-10-10.0.19045-SP0
@JesseTG JesseTG added the bug label Apr 10, 2024
@JesseTG
Copy link
Author

JesseTG commented Apr 10, 2024

I just noticed something; the offending types do not have explicit __init__ methods; they're auto-generated, probably by ctypes.Structure.

@JesseTG
Copy link
Author

JesseTG commented Apr 10, 2024

Okay, I think I have an idea of what's up. I have a lot of classes marked with @dataclass(init=False). I initially believed that init=False would conflict with whatever magic Structure provides; removing the init argument on them fixes the issue.

@mhils
Copy link
Member

mhils commented Apr 10, 2024

Thanks for tracking this down! We clearly shouldn't raise on this.

JesseTG added a commit to JesseTG/libretro.py that referenced this issue Apr 11, 2024
…o_` structs

- Turns out they weren't necessary
- Keeping them in made pdoc choke (see mitmproxy/pdoc#678)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants