Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@hmellor

Description

@hmellor

Description of the bug

signature_crossrefs is creating links from local variables used to set instance attributes, where the docs 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:

pip install mkdocs-material mkdocs-api-autonav
touch mkdocs.yml
mkdir docs
touch docs/index.md
mkdir src
touch src/__init__.py
# 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"]
<!-- docs/index.md -->
# Intro
# src/__init__.py
class Class:
    def __init__(self):
        intro = "Some text"
        self.attr = intro

Finally:

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

Metadata

Metadata

Assignees

Labels

unconfirmedThis bug was not reproduced yet

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions