ITADN

bug: `signature_crossrefs` is creating unwanted links when instance attributes set using local variables

#319Openhmellor 创建于 2025-11-15
bug
H
hmellorcommented
### Description of the bug `signature_crossrefs` is creating links from local variables used to set instance attributes, where the [docs](https://mkdocstrings.github.io/python/usage/configuration/signatures/#signature_crossrefs) say that it should only be doing it for type annotations. This becomes a problem if the local variable name matches the name of a heading somewhere else in the docs. ### To Reproduce Setup: ```bash pip install mkdocs-material mkdocs-api-autonav touch mkdocs.yml mkdir docs touch docs/index.md mkdir src touch src/__init__.py ``` ```yml # mkdocs.yml site_name: Docs theme: name: material plugins: - autorefs - mkdocstrings: handlers: python: options: show_if_no_docstring: true separate_signature: true signature_crossrefs: true - api-autonav: modules: ["src"] ``` ```md <!-- docs/index.md --> # Intro ``` ```py # src/__init__.py class Class: def __init__(self): intro = "Some text" self.attr = intro ``` Finally: - run `mkdocs serve` - open http://127.0.0.1:8000/reference/src/ - notice that: - `intro` has become a link - that link takes you to http://127.0.0.1:8000/#intro, which is unrelated ### Expected behavior This link should not have been created. ### Environment information - __System__: macOS-26.1-arm64-arm-64bit - __Python__: cpython 3.12.8 (~/.venv/bin/python) - __Environment variables__: - __Installed packages__: - `mkdocstrings-python` v1.19.0
3 条评论