Skip to content

Commit 7993a8b

Browse files
authored
Use more type aliases for autodoc event listeners (#14008)
1 parent e347e59 commit 7993a8b

File tree

4 files changed

+27
-60
lines changed

4 files changed

+27
-60
lines changed

doc/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@
185185
('js:func', 'number'),
186186
('js:func', 'string'),
187187
('py:attr', 'srcline'),
188+
# sphinx.application.Sphinx.connect
188189
('py:class', '_AutodocProcessDocstringListener'),
190+
# sphinx.application.Sphinx.connect
191+
('py:class', '_AutodocProcessSignatureListener'),
192+
('py:class', '_AutodocSkipMemberListener'), # sphinx.application.Sphinx.connect
189193
('py:class', '_ConfigRebuild'), # sphinx.application.Sphinx.add_config_value
190194
# sphinx.application.Sphinx.add_html_math_renderer
191195
('py:class', '_MathsBlockRenderers'),

sphinx/application.py

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@
5353
from sphinx.domains import Domain, Index
5454
from sphinx.environment.collectors import EnvironmentCollector
5555
from sphinx.ext.autodoc._documenters import Documenter
56-
from sphinx.ext.autodoc._event_listeners import _AutodocProcessDocstringListener
56+
from sphinx.ext.autodoc._event_listeners import (
57+
_AutodocProcessDocstringListener,
58+
_AutodocProcessSignatureListener,
59+
_AutodocSkipMemberListener,
60+
)
5761
from sphinx.ext.todo import todo_node
5862
from sphinx.extension import Extension
5963
from sphinx.registry import (
@@ -725,20 +729,7 @@ def connect(
725729
def connect(
726730
self,
727731
event: Literal['autodoc-process-signature'],
728-
callback: Callable[
729-
[
730-
Sphinx,
731-
Literal[
732-
'module', 'class', 'exception', 'function', 'method', 'attribute'
733-
],
734-
str,
735-
Any,
736-
dict[str, bool],
737-
str | None,
738-
str | None,
739-
],
740-
tuple[str | None, str | None] | None,
741-
],
732+
callback: _AutodocProcessSignatureListener,
742733
priority: int = 500,
743734
) -> int: ...
744735

@@ -754,19 +745,7 @@ def connect(
754745
def connect(
755746
self,
756747
event: Literal['autodoc-skip-member'],
757-
callback: Callable[
758-
[
759-
Sphinx,
760-
Literal[
761-
'module', 'class', 'exception', 'function', 'method', 'attribute'
762-
],
763-
str,
764-
Any,
765-
bool,
766-
dict[str, bool],
767-
],
768-
bool,
769-
],
748+
callback: _AutodocSkipMemberListener,
770749
priority: int = 500,
771750
) -> int: ...
772751

sphinx/events.py

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
from sphinx.config import Config
2929
from sphinx.domains import Domain
3030
from sphinx.environment import BuildEnvironment
31-
from sphinx.ext.autodoc._event_listeners import _AutodocProcessDocstringListener
31+
from sphinx.ext.autodoc._event_listeners import (
32+
_AutodocProcessDocstringListener,
33+
_AutodocProcessSignatureListener,
34+
_AutodocSkipMemberListener,
35+
)
3236
from sphinx.ext.todo import todo_node
3337

3438

@@ -291,20 +295,7 @@ def connect(
291295
def connect(
292296
self,
293297
name: Literal['autodoc-process-signature'],
294-
callback: Callable[
295-
[
296-
Sphinx,
297-
Literal[
298-
'module', 'class', 'exception', 'function', 'method', 'attribute'
299-
],
300-
str,
301-
Any,
302-
dict[str, bool],
303-
str | None,
304-
str | None,
305-
],
306-
tuple[str | None, str | None] | None,
307-
],
298+
callback: _AutodocProcessSignatureListener,
308299
priority: int,
309300
) -> int: ...
310301

@@ -320,19 +311,7 @@ def connect(
320311
def connect(
321312
self,
322313
name: Literal['autodoc-skip-member'],
323-
callback: Callable[
324-
[
325-
Sphinx,
326-
Literal[
327-
'module', 'class', 'exception', 'function', 'method', 'attribute'
328-
],
329-
str,
330-
Any,
331-
bool,
332-
dict[str, bool],
333-
],
334-
bool,
335-
],
314+
callback: _AutodocSkipMemberListener,
336315
priority: int,
337316
) -> int: ...
338317

sphinx/ext/autodoc/_event_listeners.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@
77

88
if TYPE_CHECKING:
99
from collections.abc import Callable, Sequence
10-
from typing import Any, Literal, TypeAlias
10+
from typing import Any, TypeAlias
1111

1212
from sphinx.application import Sphinx
13+
from sphinx.ext.autodoc._property_types import _AutodocObjType
1314

14-
_AutodocObjType = Literal[
15-
'module', 'class', 'exception', 'function', 'method', 'attribute'
16-
]
1715
_AutodocProcessDocstringListener: TypeAlias = Callable[
1816
[Sphinx, _AutodocObjType, str, Any, dict[str, bool], list[str]], None
1917
]
18+
_AutodocProcessSignatureListener: TypeAlias = Callable[ # NoQA: PYI047
19+
[Sphinx, _AutodocObjType, str, Any, dict[str, bool], str | None, str | None],
20+
tuple[str | None, str | None] | None,
21+
]
22+
_AutodocSkipMemberListener: TypeAlias = Callable[ # NoQA: PYI047
23+
[Sphinx, _AutodocObjType, str, Any, bool, dict[str, bool]], bool
24+
]
2025

2126

2227
def cut_lines(

0 commit comments

Comments
 (0)