(app: sphinx.application.Sphinx)
| 282 | |
| 283 | |
| 284 | def setup(app: sphinx.application.Sphinx) -> None: |
| 285 | app.add_crossref_type( |
| 286 | "fixture", |
| 287 | "fixture", |
| 288 | objname="built-in fixture", |
| 289 | indextemplate="pair: %s; fixture", |
| 290 | ) |
| 291 | |
| 292 | app.add_object_type( |
| 293 | "globalvar", |
| 294 | "globalvar", |
| 295 | objname="global variable interpreted by pytest", |
| 296 | indextemplate="pair: %s; global variable interpreted by pytest", |
| 297 | ) |
| 298 | |
| 299 | app.add_crossref_type( |
| 300 | directivename="hook", |
| 301 | rolename="hook", |
| 302 | objname="pytest hook", |
| 303 | indextemplate="pair: %s; hook", |
| 304 | ) |
| 305 | |
| 306 | # legacypath.py monkey-patches pytest.Testdir in. Import the file so |
| 307 | # that autodoc can discover references to it. |
| 308 | # Workaround for Sphinx bug with Python 3.14: |
| 309 | # inspect.getsource() returns '\n' instead of raising OSError for classes |
| 310 | # whose __module__ doesn't match the file they're defined in, causing |
| 311 | # get_type_comment() to crash with IndexError on empty ast.parse result. |
| 312 | # See: https://github.com/sphinx-doc/sphinx/issues/14345 |
| 313 | import sys |
| 314 | |
| 315 | import _pytest.legacypath # noqa: F401 |
| 316 | |
| 317 | if sys.version_info >= (3, 14): |
| 318 | from sphinx.ext.autodoc._dynamic import _type_comments |
| 319 | |
| 320 | _orig_get_type_comment = _type_comments.get_type_comment |
| 321 | |
| 322 | def _get_type_comment_safe(obj: object, bound_method: bool = False) -> object: |
| 323 | try: |
| 324 | return _orig_get_type_comment(obj, bound_method) |
| 325 | except IndexError: |
| 326 | return None |
| 327 | |
| 328 | _type_comments.get_type_comment = _get_type_comment_safe # type: ignore[assignment] |
no outgoing calls