[BUG] MemoryError
in sphinx.ext.intersphinx
and undesirable side-effects in domains.
#11337
Milestone
MemoryError
in sphinx.ext.intersphinx
and undesirable side-effects in domains.
#11337
Describe the bug
As mentioned in #11282 (comment), I found that
sphinx.ext.intersphinx
has a serious bug when parsing a document with the following structure:As I said, here what happens during the resolution phase:
sphinx/sphinx/domains/python.py
Lines 1328 to 1331 in 39fa276
In particular, when encountering
typing.*
orNone
in an inline reference such as:type NAME: TYPE
, the latter will be considered as anobj
reference (and not aclass
reference). This is due tosphinx/sphinx/domains/python.py
Lines 96 to 100 in 39fa276
Now, if
sphinx.ext.intersphinx
is enabled, we have:sphinx/sphinx/ext/intersphinx.py
Lines 355 to 370 in 5a6b2b1
I found the following issues:
py:obj
, the corresponding object types are all possible object types. In particular,'attribute'
and'method'
coexist and'method'
will be duplicated. This can lead to aMemoryError
(I had a medium-size project whereobject_types
grow more than of a hundred times so I can imagine when there are VERY large projects).sphinx/sphinx/ext/intersphinx.py
Lines 422 to 429 in 5a6b2b1
objtypes
list isdomain._role2type[typ]
. This means that any modification to the former propagate to the latter, thereby causing an undesirable side-effect. Note that this currently seems to only affect thepy:obj
role but the side-effect can also be seen for other property-like roles.With my above example, the domain's role dispatcher map grows as follows:
How to Reproduce
conf.py
index.rst
Environment Information
Sphinx extensions
['sphinx.ext.intersphinx']
Additional context
The text was updated successfully, but these errors were encountered: