Skip to content

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

Description

@pawamoy

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

/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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