Skip to content

Commit 4d795fe

Browse files
committed
docs(conf): Fix mypy attr-defined error on py_domain.find_obj
why: env.get_domain() returns Domain, the base class, which does not declare find_obj(). mypy correctly flags this as an attr-defined error because find_obj is defined only on PythonDomain. what: - Import PythonDomain from sphinx.domains.python under TYPE_CHECKING - Annotate py_domain as PythonDomain with a type: ignore[assignment] comment to satisfy mypy while keeping the cast lightweight at runtime
1 parent ad6251a commit 4d795fe

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from docutils import nodes
1111
from sphinx import addnodes
1212
from sphinx.application import Sphinx
13+
from sphinx.domains.python import PythonDomain
1314
from sphinx.environment import BuildEnvironment
1415

1516
from gp_sphinx.config import make_linkcode_resolve, merge_sphinx_config
@@ -73,7 +74,7 @@ def _on_missing_class_reference(
7374
return None
7475
from sphinx.util.nodes import make_refnode
7576

76-
py_domain = env.get_domain("py")
77+
py_domain: PythonDomain = env.get_domain("py") # type: ignore[assignment]
7778
target = node.get("reftarget", "")
7879
matches = py_domain.find_obj(env, "", "", target, None, 1)
7980
if not matches:

0 commit comments

Comments
 (0)