Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add monkey patch to fix source file/line number info for object descr…
…iptions This addresses the issue described at sphinx-doc/sphinx#11147.
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Monkey patches a fix for https://github.com/sphinx-doc/sphinx/pull/11147.""" | ||
|
||
import inspect | ||
|
||
import sphinx.util.nodes | ||
import sphinx.util.docutils | ||
|
||
|
||
def _monkey_patch_nested_parse_with_titles(): | ||
orig_nested_parse_with_titles = sphinx.util.nodes.nested_parse_with_titles | ||
|
||
if list(inspect.signature(orig_nested_parse_with_titles).parameters.keys()) != [ | ||
"state", | ||
"content", | ||
"node", | ||
]: | ||
# Assume https://github.com/sphinx-doc/sphinx/pull/11147 has been merged. | ||
return | ||
|
||
# Note that this is different from the fix in | ||
# https://github.com/sphinx-doc/sphinx/pull/11147, since it is not practical | ||
# to monkey patch all callers to pass in the `content_offset`. Instead, we | ||
# use `switch_source_input`, which makes it unnecessary to pass in | ||
# `content_offset`. | ||
def nested_parse_with_titles(state, content, node): | ||
with sphinx.util.docutils.switch_source_input(state, content): | ||
return orig_nested_parse_with_titles(state, content, node) | ||
|
||
sphinx.util.nodes.nested_parse_with_titles = nested_parse_with_titles |