Skip to content

Commit 5a69e05

Browse files
committed
refactor: generators are Iterable unless they are contextmanagers
1 parent bf7c64b commit 5a69e05

File tree

10 files changed

+18
-19
lines changed

10 files changed

+18
-19
lines changed

coverage/bytecode.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77

88
import collections
99
import dis
10-
from collections.abc import Iterator
1110
from types import CodeType
1211
from typing import Iterable, Optional
1312

1413
from coverage.types import TArc, TOffset
1514

1615

17-
def code_objects(code: CodeType) -> Iterator[CodeType]:
16+
def code_objects(code: CodeType) -> Iterable[CodeType]:
1817
"""Iterate over all the code objects in `code`."""
1918
stack = [code]
2019
while stack:

coverage/debug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def info_header(label: str) -> str:
139139
return "--{:-<60s}".format(" " + label + " ")
140140

141141

142-
def info_formatter(info: Iterable[tuple[str, Any]]) -> Iterator[str]:
142+
def info_formatter(info: Iterable[tuple[str, Any]]) -> Iterable[str]:
143143
"""Produce a sequence of formatted lines from info.
144144
145145
`info` is a sequence of pairs (label, data). The produced lines are

coverage/report_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from __future__ import annotations
77

88
import sys
9-
from collections.abc import Iterable, Iterator
9+
from collections.abc import Iterable
1010
from typing import IO, TYPE_CHECKING, Callable, Protocol
1111

1212
from coverage.exceptions import NoDataError, NotPython
@@ -71,7 +71,7 @@ def render_report(
7171
def get_analysis_to_report(
7272
coverage: Coverage,
7373
morfs: Iterable[TMorf] | None,
74-
) -> Iterator[tuple[FileReporter, Analysis]]:
74+
) -> Iterable[tuple[FileReporter, Analysis]]:
7575
"""Get the files to report on.
7676
7777
For each morf in `morfs`, if it should be reported on (based on the omit

tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import sys
1414
import warnings
1515

16-
from collections.abc import Iterator
16+
from collections.abc import Iterable
1717

1818
import pytest
1919

@@ -64,15 +64,15 @@ def set_warnings() -> None:
6464

6565

6666
@pytest.fixture(autouse=True)
67-
def reset_sys_path() -> Iterator[None]:
67+
def reset_sys_path() -> Iterable[None]:
6868
"""Clean up sys.path changes around every test."""
6969
sys_path = list(sys.path)
7070
yield
7171
sys.path[:] = sys_path
7272

7373

7474
@pytest.fixture(autouse=True)
75-
def reset_environment() -> Iterator[None]:
75+
def reset_environment() -> Iterable[None]:
7676
"""Make sure a test setting an envvar doesn't leak into another test."""
7777
old_environ = os.environ.copy()
7878
yield
@@ -96,7 +96,7 @@ def force_local_pyc_files() -> None:
9696

9797
# Give this an underscored name so pylint won't complain when we use the fixture.
9898
@pytest.fixture(name="_create_pth_file")
99-
def create_pth_file_fixture() -> Iterator[None]:
99+
def create_pth_file_fixture() -> Iterable[None]:
100100
"""Create and clean up a .pth file for tests that need it for subprocesses."""
101101
pth_files = create_pth_files()
102102
try:

tests/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def get_output(self) -> str:
399399
return self.io.getvalue()
400400

401401

402-
def all_our_source_files() -> Iterator[tuple[Path, str]]:
402+
def all_our_source_files() -> Iterable[tuple[Path, str]]:
403403
"""Iterate over all of our own source files.
404404
405405
This is used in tests that need a bunch of Python code to analyze, so we

tests/mixins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import os.path
1515
import sys
1616

17-
from collections.abc import Iterable, Iterator
17+
from collections.abc import Iterable
1818
from typing import Any, Callable, cast
1919

2020
import pytest
@@ -64,7 +64,7 @@ class TempDirMixin:
6464
run_in_temp_dir = True
6565

6666
@pytest.fixture(autouse=True)
67-
def _temp_dir(self, tmp_path_factory: pytest.TempPathFactory) -> Iterator[None]:
67+
def _temp_dir(self, tmp_path_factory: pytest.TempPathFactory) -> Iterable[None]:
6868
"""Create a temp dir for the tests, if they want it."""
6969
if self.run_in_temp_dir:
7070
tmpdir = tmp_path_factory.mktemp("t")

tests/test_files.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import re
1212

1313
from typing import Any, Protocol
14-
from collections.abc import Iterable, Iterator
14+
from collections.abc import Iterable
1515
from unittest import mock
1616

1717
import pytest
@@ -149,7 +149,7 @@ def globs_to_regex_params(
149149
partial: bool = False,
150150
matches: Iterable[str] = (),
151151
nomatches: Iterable[str] = (),
152-
) -> Iterator[Any]:
152+
) -> Iterable[Any]:
153153
"""Generate parameters for `test_globs_to_regex`.
154154
155155
`patterns`, `case_insensitive`, and `partial` are arguments for

tests/test_html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ def html_data_from_cov(self, cov: Coverage, morf: TMorf) -> coverage.html.FileDa
14421442
"""Get HTML report data from a `Coverage` object for a morf."""
14431443
with self.assert_warnings(cov, []):
14441444
datagen = coverage.html.HtmlDataGeneration(cov)
1445-
fr, analysis = next(get_analysis_to_report(cov, [morf]))
1445+
fr, analysis = next(iter(get_analysis_to_report(cov, [morf])))
14461446
file_data = datagen.data_for_file(fr, analysis)
14471447
return file_data
14481448

tests/test_venv.py

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

1212
from pathlib import Path
1313
from typing import cast
14-
from collections.abc import Iterator
14+
from collections.abc import Iterable
1515

1616
import pytest
1717

@@ -208,7 +208,7 @@ class VirtualenvTest(CoverageTest):
208208
expected_stdout = "33\n110\n198\n1.5\n"
209209

210210
@pytest.fixture(autouse=True)
211-
def in_venv_world_fixture(self, venv_world: Path) -> Iterator[None]:
211+
def in_venv_world_fixture(self, venv_world: Path) -> Iterable[None]:
212212
"""For running tests inside venv_world, and cleaning up made files."""
213213
with change_dir(venv_world):
214214
self.make_file(

tests/test_xml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import re
1111

1212
from typing import Any
13-
from collections.abc import Iterator
13+
from collections.abc import Iterable
1414
from xml.etree import ElementTree
1515

1616
import pytest
@@ -383,7 +383,7 @@ def unbackslash(v: Any) -> Any:
383383
class XmlPackageStructureTest(XmlTestHelpers, CoverageTest):
384384
"""Tests about the package structure reported in the coverage.xml file."""
385385

386-
def package_and_class_tags(self, cov: Coverage) -> Iterator[tuple[str, dict[str, Any]]]:
386+
def package_and_class_tags(self, cov: Coverage) -> Iterable[tuple[str, dict[str, Any]]]:
387387
"""Run an XML report on `cov`, and get the package and class tags."""
388388
cov.xml_report()
389389
dom = ElementTree.parse("coverage.xml")

0 commit comments

Comments
 (0)