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

bug: TypeError: '<' not supported between instances of 'NoneType' and 'int' when rendering source #163

Closed
pawamoy opened this issue May 15, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@pawamoy
Copy link
Member

pawamoy commented May 15, 2024

Description of the bug

If a Griffe object has its lineno attribute set to None, rendering its source will fail.

To Reproduce

Add a Griffe extension that adds a member, created manually (in the extension) without a lineno.
Render it in the docs. Enable show_source: true.

Full traceback

Full traceback
  File "/home/pawamoy/data/dev/qtile/.venv/lib/python3.12/site-packages/mkdocstrings_handlers/python/templates/material/_base/function.html", line 99, in block 'source'
    {{ function.source|highlight(language="python", linestart=function.lineno, linenums=True) }}
^^^^^^^^^^^^^^^^^
  File "/home/pawamoy/data/dev/qtile/.venv/lib/python3.12/site-packages/mkdocstrings/handlers/rendering.py", line 120, in highlight
    result = super().highlight(src, language, inline=inline, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pawamoy/data/dev/qtile/.venv/lib/python3.12/site-packages/pymdownx/highlight.py", line 385, in highlight
    if not linenums or linestart < 1:
                       ^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'NoneType' and 'int'

Expected behavior

Rendering the source shouldn't make MkDocs crash, even if lineno is None.

Environment information

python -m mkdocstrings_handlers.python.debug  # | xclip -selection clipboard
  • System: Linux-6.8.9-arch1-2-x86_64-with-glibc2.39
  • Python: cpython 3.12.1 (/home/pawamoy/data/dev/qtile/.venv/bin/python)
  • Environment variables:
    • PYTHONPATH: /home/pawamoy/.local/pipx/venvs/pdm/lib/python3.11/site-packages/pdm/pep582
  • Installed packages:
    • mkdocs v1.6.0
    • mkdocstrings v0.25.1
    • mkdocstrings-python v1.10.0.1.8.1
    • griffe v0.45.0

Additional context

/

@pawamoy pawamoy added the unconfirmed This bug was not reproduced yet label May 15, 2024
@pawamoy pawamoy self-assigned this May 15, 2024
@pawamoy pawamoy added bug Something isn't working and removed unconfirmed This bug was not reproduced yet labels May 22, 2024
pawamoy added a commit that referenced this issue May 22, 2024
@pawamoy pawamoy closed this as completed May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant