Skip to content

py:method with :property: registers index entry with parens; should not (swev-id: sphinx-doc__sphinx-9698) #89

@rowan-stein

Description

@rowan-stein

User request

An index entry with parens was registered for py:method directive with :property: option.

Describe the bug

An index entry with parens was registered for py:method directive with :property: option. It should not have parens.

How to Reproduce

# index.rst

.. py:method:: Foo.bar
   :property:

.. py:property:: Foo.baz

Expected behavior

An index entry for the property should not have parens.

Your project

N/A

Screenshots

スクリーンショット 2021-10-03 13 00 53

OS

Mac

Python version

3.9.6

Sphinx version

HEAD of 4.x

Sphinx extensions

No response

Extra tools

No response

Additional context

No response


Researcher specification (Emerson Gray)

Scope: Update Python domain’s index text formatting for py:method when used with :property: to omit parentheses, matching py:property behavior.

  • Primary file: sphinx/domains/python.py
  • Class/Method: PyMethod.get_index_text(self, modname, name_cls)
  • Current issue: get_index_text appends () unconditionally, including the property branch: return _('%s() (%s property)') % (methname, clsname).
  • Required change: when 'property' in self.options, return text without ():
    • Class/member branch: '%(meth)s (%(cls)s property)'.
    • Fallback no-dot (ValueError) branch: also omit (); if modname present, use 'name (in module modname)', else 'name'.
  • Do not modify PyObject.add_target_and_index, PyProperty, inventory (objects.inv), or cross-reference logic.
  • needs_arglist() already returns False for properties; signatures remain without parentheses.

Tests

  • Unit: Update tests/test_domain_py.py::test_pymethod_options to expect 'meth5 (Class property)' instead of 'meth5() (Class property)' for py:method with :property:.
  • Optional unit: Add an edge-case test for py:method with :property: outside a class (no-dot branch) to ensure no ().
  • Functional: Use the reproduction snippet above; ensure generated index lists show bar (Foo property) and baz (Foo property) without ().

Side effects/regressions

  • Regular methods, classmethod, and staticmethod should continue to include ().
  • py:property behavior remains unchanged.
  • Inventory and cross-references unaffected; only index text formatting changes.

Verification

  • Run pytest tests/test_domain_py.py::test_pymethod_options.
  • Optionally build HTML for a small project containing the snippet and verify genindex entry strings.

Metadata

Metadata

Assignees

No one assigned

    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