Skip to content

Commit

Permalink
Add python_strip_property_prefix config option
Browse files Browse the repository at this point in the history
  • Loading branch information
jbms committed May 6, 2022
1 parent ddd0a5b commit 55a6bb7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ Python domain customization

Does something with the object.

.. confval:: python_strip_property_prefix

Strip the ``property`` prefix from :rst:dir:`py:property` object
descriptions.

Overloaded functions
--------------------

Expand Down
18 changes: 17 additions & 1 deletion sphinx_immaterial/python_domain_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Optional,
Any,
Iterator,
Union,
)

import docutils.nodes
Expand Down Expand Up @@ -144,10 +145,22 @@ def _monkey_patch_python_get_signature_prefix(
) -> None:
orig_get_signature_prefix = directive_cls.get_signature_prefix

def get_signature_prefix(self, sig: str) -> str:
def get_signature_prefix(self, sig: str) -> Union[str, List[docutils.nodes.Node]]:
prefix = orig_get_signature_prefix(self, sig)
if not self.env.config.python_strip_property_prefix:
return prefix
if sphinx.version_info >= (4, 3):
assert isinstance(prefix, list)
for prop_idx, node in enumerate(prefix):
if node == "property":
assert isinstance(
prefix[prop_idx + 1], sphinx.addnodes.desc_sig_space
)
prefix = list(prefix)
del prefix[prop_idx : prop_idx + 2]
break
return prefix
assert isinstance(prefix, str)
parts = prefix.strip().split(" ")
if "property" in parts:
parts.remove("property")
Expand Down Expand Up @@ -860,6 +873,9 @@ def setup(app: sphinx.application.Sphinx):
rebuild="env",
types=(re.Pattern, type(None)),
)
app.add_config_value(
"python_strip_property_prefix", default=False, rebuild="env", types=(bool,)
)
app.connect("config-inited", _config_inited)

return {
Expand Down

0 comments on commit 55a6bb7

Please sign in to comment.