Skip to content

Commit 3a02703

Browse files
committed
mypy: test_debug.py test_execfile.py test_filereporter.py test_files.py
1 parent 7b48747 commit 3a02703

12 files changed

+175
-144
lines changed

coverage/config.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
from coverage.exceptions import ConfigError
1919
from coverage.misc import isolate_module, human_sorted_items, substitute_variables
2020
from coverage.tomlconfig import TomlConfigParser, TomlDecodeError
21-
from coverage.types import TConfigurable, TConfigSection, TConfigValue
21+
from coverage.types import (
22+
TConfigurable, TConfigSectionIn, TConfigValueIn, TConfigSectionOut, TConfigValueOut,
23+
)
2224

2325
os = isolate_module(os)
2426

@@ -71,9 +73,9 @@ def options(self, section: str) -> List[str]:
7173
return super().options(real_section)
7274
raise ConfigError(f"No section: {section!r}")
7375

74-
def get_section(self, section: str) -> TConfigSection:
76+
def get_section(self, section: str) -> TConfigSectionOut:
7577
"""Get the contents of a section, as a dictionary."""
76-
d: Dict[str, TConfigValue] = {}
78+
d: Dict[str, TConfigValueOut] = {}
7779
for opt in self.options(section):
7880
d[opt] = self.get(section, opt)
7981
return d
@@ -249,15 +251,15 @@ def __init__(self) -> None:
249251
self.paths: Dict[str, List[str]] = {}
250252

251253
# Options for plugins
252-
self.plugin_options: Dict[str, TConfigSection] = {}
254+
self.plugin_options: Dict[str, TConfigSectionOut] = {}
253255

254256
MUST_BE_LIST = {
255257
"debug", "concurrency", "plugins",
256258
"report_omit", "report_include",
257259
"run_omit", "run_include",
258260
}
259261

260-
def from_args(self, **kwargs: TConfigValue) -> None:
262+
def from_args(self, **kwargs: TConfigValueIn) -> None:
261263
"""Read config values from `kwargs`."""
262264
for k, v in kwargs.items():
263265
if v is not None:
@@ -441,11 +443,11 @@ def _set_attr_from_config_option(
441443
return True
442444
return False
443445

444-
def get_plugin_options(self, plugin: str) -> TConfigSection:
446+
def get_plugin_options(self, plugin: str) -> TConfigSectionOut:
445447
"""Get a dictionary of options for the plugin named `plugin`."""
446448
return self.plugin_options.get(plugin, {})
447449

448-
def set_option(self, option_name: str, value: Union[TConfigValue, TConfigSection]) -> None:
450+
def set_option(self, option_name: str, value: Union[TConfigValueIn, TConfigSectionIn]) -> None:
449451
"""Set an option in the configuration.
450452
451453
`option_name` is a colon-separated string indicating the section and
@@ -476,7 +478,7 @@ def set_option(self, option_name: str, value: Union[TConfigValue, TConfigSection
476478
# If we get here, we didn't find the option.
477479
raise ConfigError(f"No such option: {option_name!r}")
478480

479-
def get_option(self, option_name: str) -> Optional[TConfigValue]:
481+
def get_option(self, option_name: str) -> Optional[TConfigValueOut]:
480482
"""Get an option from the configuration.
481483
482484
`option_name` is a colon-separated string indicating the section and
@@ -559,7 +561,7 @@ def config_files_to_try(config_file: Union[bool, str]) -> List[Tuple[str, bool,
559561
def read_coverage_config(
560562
config_file: Union[bool, str],
561563
warn: Callable[[str], None],
562-
**kwargs: TConfigValue,
564+
**kwargs: TConfigValueIn,
563565
) -> CoverageConfig:
564566
"""Read the coverage.py configuration.
565567

coverage/control.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,16 @@
4747
from coverage.results import Analysis
4848
from coverage.summary import SummaryReporter
4949
from coverage.types import (
50-
TConfigurable, TConfigSection, TConfigValue, TFileDisposition, TLineNo, TMorf,
50+
TConfigurable, TConfigSectionIn, TConfigValueIn, TConfigValueOut,
51+
TFileDisposition, TLineNo, TMorf,
5152
)
5253
from coverage.xmlreport import XmlReporter
5354

5455

5556
os = isolate_module(os)
5657

5758
@contextlib.contextmanager
58-
def override_config(cov: Coverage, **kwargs: TConfigValue) -> Generator[None, None, None]:
59+
def override_config(cov: Coverage, **kwargs: TConfigValueIn) -> Generator[None, None, None]:
5960
"""Temporarily tweak the configuration of `cov`.
6061
6162
The arguments are applied to `cov.config` with the `from_args` method.
@@ -120,12 +121,12 @@ def __init__( # pylint: disable=too-many-arguments
120121
timid: Optional[bool]=None,
121122
branch: Optional[bool]=None,
122123
config_file: Union[str, bool]=True,
123-
source: Optional[List[str]]=None,
124-
source_pkgs: Optional[List[str]]=None,
125-
omit: Optional[Union[str, List[str]]]=None,
126-
include: Optional[Union[str, List[str]]]=None,
127-
debug: Optional[List[str]]=None,
128-
concurrency: Optional[Union[str, List[str]]]=None,
124+
source: Optional[Iterable[str]]=None,
125+
source_pkgs: Optional[Iterable[str]]=None,
126+
omit: Optional[Union[str, Iterable[str]]]=None,
127+
include: Optional[Union[str, Iterable[str]]]=None,
128+
debug: Optional[Iterable[str]]=None,
129+
concurrency: Optional[Union[str, Iterable[str]]]=None,
129130
check_preimported: bool=False,
130131
context: Optional[str]=None,
131132
messages: bool=False,
@@ -425,7 +426,7 @@ def _message(self, msg: str) -> None:
425426
if self._messages:
426427
print(msg)
427428

428-
def get_option(self, option_name: str) -> Optional[TConfigValue]:
429+
def get_option(self, option_name: str) -> Optional[TConfigValueOut]:
429430
"""Get an option from the configuration.
430431
431432
`option_name` is a colon-separated string indicating the section and
@@ -443,7 +444,7 @@ def get_option(self, option_name: str) -> Optional[TConfigValue]:
443444
"""
444445
return self.config.get_option(option_name)
445446

446-
def set_option(self, option_name: str, value: Union[TConfigValue, TConfigSection]) -> None:
447+
def set_option(self, option_name: str, value: Union[TConfigValueIn, TConfigSectionIn]) -> None:
447448
"""Set an option in the configuration.
448449
449450
`option_name` is a colon-separated string indicating the section and

coverage/files.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def _glob_to_regex(pattern: str) -> str:
351351
def globs_to_regex(
352352
patterns: Iterable[str],
353353
case_insensitive: bool=False,
354-
partial: bool=False
354+
partial: bool=False,
355355
) -> re.Pattern[str]:
356356
"""Convert glob patterns to a compiled regex that matches any of them.
357357

coverage/tomlconfig.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from coverage import env
1212
from coverage.exceptions import ConfigError
1313
from coverage.misc import import_third_party, substitute_variables
14-
from coverage.types import TConfigSection, TConfigValue
14+
from coverage.types import TConfigSectionOut, TConfigValueOut
1515

1616

1717
if env.PYVERSION >= (3, 11, 0, "alpha", 7):
@@ -65,7 +65,7 @@ def read(self, filenames: Iterable[str]) -> List[str]:
6565
raise ConfigError(msg.format(filename))
6666
return []
6767

68-
def _get_section(self, section: str) -> Tuple[Optional[str], Optional[TConfigSection]]:
68+
def _get_section(self, section: str) -> Tuple[Optional[str], Optional[TConfigSectionOut]]:
6969
"""Get a section from the data.
7070
7171
Arguments:
@@ -92,7 +92,7 @@ def _get_section(self, section: str) -> Tuple[Optional[str], Optional[TConfigSec
9292
return None, None
9393
return real_section, data
9494

95-
def _get(self, section: str, option: str) -> Tuple[str, TConfigValue]:
95+
def _get(self, section: str, option: str) -> Tuple[str, TConfigValueOut]:
9696
"""Like .get, but returns the real section name and the value."""
9797
name, data = self._get_section(section)
9898
if data is None:
@@ -135,7 +135,7 @@ def options(self, section: str) -> List[str]:
135135
raise ConfigError(f"No section: {section!r}")
136136
return list(data.keys())
137137

138-
def get_section(self, section: str) -> TConfigSection:
138+
def get_section(self, section: str) -> TConfigSectionOut:
139139
_, data = self._get_section(section)
140140
return data or {}
141141

coverage/types.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,16 @@ def get_stats(self) -> Optional[Dict[str, int]]:
107107
## Configuration
108108

109109
# One value read from a config file.
110-
TConfigValue = Optional[Union[bool, int, float, str, List[str]]]
110+
TConfigValueIn = Optional[Union[bool, int, float, str, Iterable[str]]]
111+
TConfigValueOut = Optional[Union[bool, int, float, str, List[str]]]
111112
# An entire config section, mapping option names to values.
112-
TConfigSection = Mapping[str, TConfigValue]
113+
TConfigSectionIn = Mapping[str, TConfigValueIn]
114+
TConfigSectionOut = Mapping[str, TConfigValueOut]
113115

114116
class TConfigurable(Protocol):
115117
"""Something that can proxy to the coverage configuration settings."""
116118

117-
def get_option(self, option_name: str) -> Optional[TConfigValue]:
119+
def get_option(self, option_name: str) -> Optional[TConfigValueOut]:
118120
"""Get an option from the configuration.
119121
120122
`option_name` is a colon-separated string indicating the section and
@@ -125,7 +127,7 @@ def get_option(self, option_name: str) -> Optional[TConfigValue]:
125127
126128
"""
127129

128-
def set_option(self, option_name: str, value: Union[TConfigValue, TConfigSection]) -> None:
130+
def set_option(self, option_name: str, value: Union[TConfigValueIn, TConfigSectionIn]) -> None:
129131
"""Set an option in the configuration.
130132
131133
`option_name` is a colon-separated string indicating the section and

tests/test_cmdline.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from coverage.control import DEFAULT_DATAFILE
2121
from coverage.config import CoverageConfig
2222
from coverage.exceptions import _ExceptionDuringRun
23-
from coverage.types import TConfigValue
23+
from coverage.types import TConfigValueIn, TConfigValueOut
2424
from coverage.version import __url__
2525

2626
from tests.coveragetest import CoverageTest, OK, ERR, command_line
@@ -96,7 +96,7 @@ def model_object(self) -> mock.Mock:
9696
def mock_command_line(
9797
self,
9898
args: str,
99-
options: Optional[Mapping[str, TConfigValue]]=None,
99+
options: Optional[Mapping[str, TConfigValueIn]]=None,
100100
) -> Tuple[mock.Mock, int]:
101101
"""Run `args` through the command line, with a Mock.
102102
@@ -130,7 +130,7 @@ def cmd_executes(
130130
args: str,
131131
code: str,
132132
ret: int=OK,
133-
options: Optional[Mapping[str, TConfigValue]]=None,
133+
options: Optional[Mapping[str, TConfigValueIn]]=None,
134134
) -> None:
135135
"""Assert that the `args` end up executing the sequence in `code`."""
136136
called, status = self.mock_command_line(args, options=options)
@@ -1139,10 +1139,10 @@ def __init__(
11391139
self.json_result = json_report
11401140
self.lcov_result = lcov_result
11411141

1142-
def set_option(self, optname: str, optvalue: TConfigValue) -> None:
1142+
def set_option(self, optname: str, optvalue: TConfigValueIn) -> None:
11431143
self.config.set_option(optname, optvalue)
11441144

1145-
def get_option(self, optname: str) -> TConfigValue:
1145+
def get_option(self, optname: str) -> TConfigValueOut:
11461146
return self.config.get_option(optname)
11471147

11481148
def load(self) -> None:

0 commit comments

Comments
 (0)