Skip to content

Commit 09f9188

Browse files
committed
mypy: add env.py
1 parent 0bf14e2 commit 09f9188

File tree

8 files changed

+24
-20
lines changed

8 files changed

+24
-20
lines changed

coverage/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def post_process(self) -> None:
518518
for k, v in self.paths.items()
519519
)
520520

521-
def debug_info(self) -> List[Tuple[str, str]]:
521+
def debug_info(self) -> Iterable[Tuple[str, Any]]:
522522
"""Make a list of (name, value) pairs for writing debug info."""
523523
return human_sorted_items( # type: ignore
524524
(k, v) for k, v in self.__dict__.items() if not k.startswith("_")

coverage/control.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@
4646
from coverage.report import render_report
4747
from coverage.results import Analysis
4848
from coverage.summary import SummaryReporter
49-
from coverage.types import (
50-
TConfigurable, TConfigSection, TConfigValue, TLineNo, TMorf, TSysInfo,
51-
)
49+
from coverage.types import TConfigurable, TConfigSection, TConfigValue, TLineNo, TMorf
5250
from coverage.xmlreport import XmlReporter
5351

5452

@@ -1233,7 +1231,7 @@ def lcov_report(
12331231
):
12341232
return render_report(self.config.lcov_output, LcovReporter(self), morfs, self._message)
12351233

1236-
def sys_info(self) -> TSysInfo:
1234+
def sys_info(self) -> Iterable[Tuple[str, Any]]:
12371235
"""Return a list of (key, value) pairs showing internal information."""
12381236

12391237
import coverage as covmod

coverage/debug.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import types
1616
import _thread
1717

18+
from typing import Any, Callable, Iterable, Iterator, Tuple
19+
1820
from coverage.misc import isolate_module
1921

2022
os = isolate_module(os)
@@ -108,7 +110,7 @@ def info_header(label):
108110
return "--{:-<60s}".format(" "+label+" ")
109111

110112

111-
def info_formatter(info):
113+
def info_formatter(info: Iterable[Tuple[str, Any]]) -> Iterator[str]:
112114
"""Produce a sequence of formatted lines from info.
113115
114116
`info` is a sequence of pairs (label, data). The produced lines are
@@ -135,7 +137,11 @@ def info_formatter(info):
135137
yield "%*s: %s" % (label_len, label, data)
136138

137139

138-
def write_formatted_info(write, header, info):
140+
def write_formatted_info(
141+
write: Callable[[str], None],
142+
header: str,
143+
info: Iterable[Tuple[str, Any]],
144+
) -> None:
139145
"""Write a sequence of (label,data) pairs nicely.
140146
141147
`write` is a function write(str) that accepts each line of output.

coverage/env.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import platform
88
import sys
99

10+
from typing import Any, Iterable, Tuple
11+
1012
# Operating systems.
1113
WINDOWS = sys.platform == "win32"
1214
LINUX = sys.platform.startswith("linux")
@@ -21,7 +23,7 @@
2123
PYVERSION = sys.version_info + (int(platform.python_version()[-1] == "+"),)
2224

2325
if PYPY:
24-
PYPYVERSION = sys.pypy_version_info
26+
PYPYVERSION = sys.pypy_version_info # type: ignore[attr-defined]
2527

2628
# Python behavior.
2729
class PYBEHAVIOR:
@@ -134,13 +136,14 @@ class PYBEHAVIOR:
134136
TESTING = os.getenv('COVERAGE_TESTING', '') == 'True'
135137

136138

137-
def debug_info():
139+
def debug_info() -> Iterable[Tuple[str, Any]]:
138140
"""Return a list of (name, value) pairs for printing debug information."""
139141
info = [
140142
(name, value) for name, value in globals().items()
141143
if not name.startswith("_") and
142144
name not in {"PYBEHAVIOR", "debug_info"} and
143-
not isinstance(value, type(os))
145+
not isinstance(value, type(os)) and
146+
not str(value).startswith("typing.")
144147
]
145148
info += [
146149
(name, value) for name, value in PYBEHAVIOR.__dict__.items()

coverage/inorout.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import traceback
1717

1818
from types import FrameType, ModuleType
19-
from typing import cast, Iterable, List, Optional, Set, Tuple, TYPE_CHECKING
19+
from typing import cast, Any, Iterable, List, Optional, Set, Tuple, TYPE_CHECKING
2020

2121
from coverage import env
2222
from coverage.disposition import FileDisposition, disposition_init
@@ -25,7 +25,7 @@
2525
from coverage.files import prep_patterns, find_python_files, canonical_filename
2626
from coverage.misc import sys_modules_saved
2727
from coverage.python import source_for_file, source_for_morf
28-
from coverage.types import TMorf, TWarnFn, TDebugCtl, TSysInfo
28+
from coverage.types import TMorf, TWarnFn, TDebugCtl
2929

3030
if TYPE_CHECKING:
3131
from coverage.config import CoverageConfig
@@ -565,7 +565,7 @@ def _find_executable_files(self, src_dir: str) -> Iterable[Tuple[str, Optional[s
565565
continue
566566
yield file_path, plugin_name
567567

568-
def sys_info(self) -> TSysInfo:
568+
def sys_info(self) -> Iterable[Tuple[str, Any]]:
569569
"""Our information for Coverage.sys_info.
570570
571571
Returns a list of (key, value) pairs.

coverage/plugin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def coverage_init(reg, options):
121121

122122
from coverage import files
123123
from coverage.misc import _needs_to_implement
124-
from coverage.types import TArc, TConfigurable, TLineNo, TSourceTokenLines, TSysInfo
124+
from coverage.types import TArc, TConfigurable, TLineNo, TSourceTokenLines
125125

126126

127127
class CoveragePlugin:
@@ -235,7 +235,7 @@ def configure(self, config: TConfigurable) -> None:
235235
"""
236236
pass
237237

238-
def sys_info(self) -> TSysInfo:
238+
def sys_info(self) -> Iterable[Tuple[str, Any]]:
239239
"""Get a list of information useful for debugging.
240240
241241
Plug-in type: any.

coverage/types.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from types import ModuleType
99
from typing import (
10-
Any, Dict, Iterable, List, Optional, Sequence, Tuple, Union,
10+
Any, Dict, Iterable, List, Optional, Tuple, Union,
1111
TYPE_CHECKING,
1212
)
1313

@@ -81,6 +81,3 @@ def should(self, option: str) -> bool:
8181

8282
def write(self, msg: str) -> None:
8383
"""Write a line of debug output."""
84-
85-
# Data returned from sys_info()
86-
TSysInfo = Sequence[Tuple[str, Union[str, Iterable[str]]]]

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ deps =
9696
setenv =
9797
{[testenv]setenv}
9898
C__B=coverage/__init__.py coverage/__main__.py coverage/annotate.py coverage/bytecode.py
99-
C_CE=coverage/config.py coverage/context.py coverage/control.py coverage/data.py coverage/disposition.py coverage/exceptions.py
99+
C_CE=coverage/config.py coverage/context.py coverage/control.py coverage/data.py coverage/disposition.py coverage/env.py coverage/exceptions.py
100100
C_FN=coverage/files.py coverage/inorout.py coverage/jsonreport.py coverage/lcovreport.py coverage/multiproc.py coverage/numbits.py
101101
C_OP=coverage/parser.py coverage/phystokens.py coverage/plugin.py coverage/python.py
102102
C_QZ=coverage/report.py coverage/results.py coverage/sqldata.py coverage/tomlconfig.py coverage/types.py coverage/version.py

0 commit comments

Comments
 (0)