viewcode: viewcode-find-source event is emitted for each reference
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- python
- Domain
- documentation
Research direction
Reproduce the issue with conf.py, index.rst, and example.py using the sphinx.ext.autodoc and sphinx.ext.viewcode extensions. Then trace where the viewcode-find-source event is emitted and determine how to avoid repeated source lookups; done means the handler is not called once per referenced class while source viewing still works.
Written by the indexing model from the issue text.
Description
Describe the bug
viewcode: viewcode-find-source event is emitted for each reference
To Reproduce
Add an event handler.
# conf.py
def viewcode_find_source(app, modname):
print(modname)
def setup(app):
app.connect('viewcode-find-source', viewcode_find_source)
# index.rst
.. automodule:: example
:members:
:undoc-members:
# example.py
class Foo1: pass
class Foo2: pass
class Foo3: pass
class Foo4: pass
class Foo5: pass
class Foo6: pass
class Foo7: pass
class Foo8: pass
class Foo9: pass
class Foo10: pass
class Foo11: pass
class Foo12: pass
class Foo13: pass
class Foo14: pass
class Foo15: pass
class Foo16: pass
class Foo17: pass
class Foo18: pass
class Foo19: pass
class Foo20: pass
As a result, the viewcode-find-source event is called 20 times!
It seems viewcode tries to read the source code for each reference. It's a waste.
Expected behavior
It should be called as possible as less.
Your project
No
Screenshots
No
Environment info
- OS: Mac
- Python version: 3.9.1
- Sphinx version: HEAD of 3.x
- Sphinx extensions: sphinx.ext.autodoc, sphinx.ext.viewcode
- Extra tools: No
Additional context
No
- Dominant language
- Python
- Stars
- 8k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sphinx-doc/sphinx
-
type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
sphinx-doc/sphinx#14699 ·
-
type:bug type:tests
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sphinx-doc/sphinx#14678 ·
-
type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
sphinx-doc/sphinx#14659 ·
-
autodoc: IndexError formatting signature for callable data object with annotated class variable Openextensions:autodoc type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
sphinx-doc/sphinx#14576 · 2 comments ·
-
extensions:autodoc extensions:autosummary type:bug type:docs
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
sphinx-doc/sphinx#14555 · 2 comments ·
All issues in sphinx-doc/sphinx
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100