forked from sphinx-doc/sphinx
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
bugSomething isn't workingSomething isn't working
Description
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
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_textappends()unconditionally, including thepropertybranch: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
(); ifmodnamepresent, use'name (in module modname)', else'name'.
- Class/member branch:
- Do not modify
PyObject.add_target_and_index,PyProperty, inventory (objects.inv), or cross-reference logic. needs_arglist()already returnsFalsefor properties; signatures remain without parentheses.
Tests
- Unit: Update
tests/test_domain_py.py::test_pymethod_optionsto expect'meth5 (Class property)'instead of'meth5() (Class property)'forpy:methodwith:property:. - Optional unit: Add an edge-case test for
py:methodwith:property:outside a class (no-dot branch) to ensure no(). - Functional: Use the reproduction snippet above; ensure generated index lists show
bar (Foo property)andbaz (Foo property)without().
Side effects/regressions
- Regular methods,
classmethod, andstaticmethodshould continue to include(). py:propertybehavior 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
