mkdocstrings / python

A Python handler for mkdocstrings.
https://mkdocstrings.github.io/python
ISC License
190 stars 35 forks source link

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

Closed pawamoy closed 6 months ago

pawamoy commented 6 months ago

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 ```python 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

Additional context

/