Skip to content

Commit 3421e53

Browse files
authored
Narrow Generator[T, None, None] types to Iterator[T] (sphinx-doc#12241)
1 parent 413e740 commit 3421e53

File tree

20 files changed

+61
-54
lines changed

20 files changed

+61
-54
lines changed

sphinx/builders/gettext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
if TYPE_CHECKING:
2929
import os
30-
from collections.abc import Generator, Iterable
30+
from collections.abc import Iterable, Iterator
3131

3232
from docutils.nodes import Element
3333

@@ -69,7 +69,7 @@ def add(self, msg: str, origin: Element | MsgOrigin) -> None:
6969
line = -1
7070
self.metadata[msg].append((origin.source, line, origin.uid)) # type: ignore[arg-type]
7171

72-
def __iter__(self) -> Generator[Message, None, None]:
72+
def __iter__(self) -> Iterator[Message]:
7373
for message in self.messages:
7474
positions = sorted({(source, line) for source, line, uuid
7575
in self.metadata[message]})

sphinx/builders/linkcheck.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from sphinx.util.nodes import get_node_line
3030

3131
if TYPE_CHECKING:
32-
from collections.abc import Generator, Iterator
32+
from collections.abc import Iterator
3333
from typing import Any, Callable
3434

3535
from requests import Response
@@ -224,7 +224,7 @@ def __init__(self, config: Config) -> None:
224224
self.to_ignore: list[re.Pattern[str]] = list(map(re.compile,
225225
self.config.linkcheck_ignore))
226226

227-
def check(self, hyperlinks: dict[str, Hyperlink]) -> Generator[CheckResult, None, None]:
227+
def check(self, hyperlinks: dict[str, Hyperlink]) -> Iterator[CheckResult]:
228228
self.invoke_threads()
229229

230230
total_links = 0

sphinx/domains/c/_symbol.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from sphinx.util import logging
1212

1313
if TYPE_CHECKING:
14-
from collections.abc import Generator, Iterator
14+
from collections.abc import Iterator
1515

1616
from typing_extensions import Self
1717

@@ -248,7 +248,7 @@ def _find_named_symbols(self, ident: ASTIdentifier,
248248
Symbol.debug_print("recurseInAnon: ", recurseInAnon)
249249
Symbol.debug_print("searchInSiblings: ", searchInSiblings)
250250

251-
def candidates() -> Generator[Symbol, None, None]:
251+
def candidates() -> Iterator[Symbol]:
252252
s = self
253253
if Symbol.debug_lookup:
254254
Symbol.debug_print("searching in self:")

sphinx/domains/cpp/_symbol.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from sphinx.util import logging
1818

1919
if TYPE_CHECKING:
20-
from collections.abc import Generator, Iterator
20+
from collections.abc import Iterator
2121

2222
from sphinx.environment import BuildEnvironment
2323

@@ -237,7 +237,7 @@ def get_all_symbols(self) -> Iterator[Any]:
237237
yield from sChild.get_all_symbols()
238238

239239
@property
240-
def children_recurse_anon(self) -> Generator[Symbol, None, None]:
240+
def children_recurse_anon(self) -> Iterator[Symbol]:
241241
for c in self._children:
242242
yield c
243243
if not c.identOrOp.is_anon():
@@ -347,7 +347,7 @@ def matches(s: Symbol) -> bool:
347347
return False
348348
return True
349349

350-
def candidates() -> Generator[Symbol, None, None]:
350+
def candidates() -> Iterator[Symbol]:
351351
s = self
352352
if Symbol.debug_lookup:
353353
Symbol.debug_print("searching in self:")

sphinx/environment/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from sphinx.util.osutil import canon_path, os_path
2424

2525
if TYPE_CHECKING:
26-
from collections.abc import Generator, Iterator
26+
from collections.abc import Iterator
2727
from pathlib import Path
2828

2929
from docutils import nodes
@@ -524,7 +524,7 @@ def get_outdated_files(self, config_changed: bool) -> tuple[set[str], set[str],
524524

525525
return added, changed, removed
526526

527-
def check_dependents(self, app: Sphinx, already: set[str]) -> Generator[str, None, None]:
527+
def check_dependents(self, app: Sphinx, already: set[str]) -> Iterator[str]:
528528
to_rewrite: list[str] = []
529529
for docnames in self.events.emit('env-get-updated', self):
530530
to_rewrite.extend(docnames)

sphinx/ext/apidoc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from sphinx.util.template import ReSTRenderer
3333

3434
if TYPE_CHECKING:
35-
from collections.abc import Generator, Sequence
35+
from collections.abc import Iterator, Sequence
3636

3737
logger = logging.getLogger(__name__)
3838

@@ -214,7 +214,7 @@ def is_skipped_module(filename: str, opts: Any, _excludes: Sequence[re.Pattern[s
214214

215215

216216
def walk(rootpath: str, excludes: Sequence[re.Pattern[str]], opts: Any,
217-
) -> Generator[tuple[str, list[str], list[str]], None, None]:
217+
) -> Iterator[tuple[str, list[str], list[str]]]:
218218
"""Walk through the directory and list files and subdirectories up."""
219219
followlinks = getattr(opts, 'followlinks', False)
220220
includeprivate = getattr(opts, 'includeprivate', False)

sphinx/ext/autodoc/importer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
)
2626

2727
if TYPE_CHECKING:
28-
from collections.abc import Callable, Generator, Mapping
28+
from collections.abc import Callable, Iterator, Mapping
2929
from types import ModuleType
3030
from typing import Any
3131

@@ -38,7 +38,7 @@ def _filter_enum_dict(
3838
enum_class: type[Enum],
3939
attrgetter: Callable[[Any, str, Any], Any],
4040
enum_class_dict: Mapping[str, object],
41-
) -> Generator[tuple[str, type, Any], None, None]:
41+
) -> Iterator[tuple[str, type, Any]]:
4242
"""Find the attributes to document of an enumeration class.
4343
4444
The output consists of triplets ``(attribute name, defining class, value)``

sphinx/ext/autodoc/mock.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from sphinx.util.inspect import isboundmethod, safe_getattr
1515

1616
if TYPE_CHECKING:
17-
from collections.abc import Generator, Iterator, Sequence
17+
from collections.abc import Iterator, Sequence
1818

1919
logger = logging.getLogger(__name__)
2020

@@ -137,7 +137,7 @@ def invalidate_caches(self) -> None:
137137

138138

139139
@contextlib.contextmanager
140-
def mock(modnames: list[str]) -> Generator[None, None, None]:
140+
def mock(modnames: list[str]) -> Iterator[None]:
141141
"""Insert mock modules during context::
142142
143143
with mock(['target.module.name']):

sphinx/ext/viewcode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from sphinx.util.nodes import make_refnode
2323

2424
if TYPE_CHECKING:
25-
from collections.abc import Generator, Iterable
25+
from collections.abc import Iterable, Iterator
2626

2727
from sphinx.application import Sphinx
2828
from sphinx.builders import Builder
@@ -239,7 +239,7 @@ def should_generate_module_page(app: Sphinx, modname: str) -> bool:
239239
return True
240240

241241

242-
def collect_pages(app: Sphinx) -> Generator[tuple[str, dict[str, Any], str], None, None]:
242+
def collect_pages(app: Sphinx) -> Iterator[tuple[str, dict[str, Any], str]]:
243243
env = app.builder.env
244244
if not hasattr(env, '_viewcode_modules'):
245245
return

sphinx/testing/fixtures.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from sphinx.testing.util import SphinxTestApp, SphinxTestAppWrapperForSkipBuilding
1515

1616
if TYPE_CHECKING:
17-
from collections.abc import Callable, Generator
17+
from collections.abc import Callable, Iterator
1818
from pathlib import Path
1919
from typing import Any
2020

@@ -147,7 +147,7 @@ def app(
147147
app_params: tuple[dict, dict],
148148
make_app: Callable,
149149
shared_result: SharedResult,
150-
) -> Generator[SphinxTestApp, None, None]:
150+
) -> Iterator[SphinxTestApp]:
151151
"""
152152
Provides the 'sphinx.application.Sphinx' object
153153
"""
@@ -183,7 +183,7 @@ def warning(app: SphinxTestApp) -> StringIO:
183183

184184

185185
@pytest.fixture()
186-
def make_app(test_params: dict, monkeypatch: Any) -> Generator[Callable, None, None]:
186+
def make_app(test_params: dict, monkeypatch: Any) -> Iterator[Callable]:
187187
"""
188188
Provides make_app function to initialize SphinxTestApp instance.
189189
if you want to initialize 'app' in your test function. please use this
@@ -289,7 +289,7 @@ def sphinx_test_tempdir(tmp_path_factory: Any) -> Path:
289289

290290

291291
@pytest.fixture()
292-
def rollback_sysmodules() -> Generator[None, None, None]: # NoQA: PT004
292+
def rollback_sysmodules() -> Iterator[None]: # NoQA: PT004
293293
"""
294294
Rollback sys.modules to its value before testing to unload modules
295295
during tests.

0 commit comments

Comments
 (0)