diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2023-01-04 21:09:42 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2023-01-04 21:09:42 -0500 |
commit | 3a02703108831a554ec893b9031dcebe377fdd89 (patch) | |
tree | e2b579730daf750c05bfb2e0ee0596e0fa47079b /coverage | |
parent | 7b487470d0cccaf12d06cc363318c9b5eca6985f (diff) | |
download | python-coveragepy-git-3a02703108831a554ec893b9031dcebe377fdd89.tar.gz |
mypy: test_debug.py test_execfile.py test_filereporter.py test_files.py
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/config.py | 20 | ||||
-rw-r--r-- | coverage/control.py | 21 | ||||
-rw-r--r-- | coverage/files.py | 2 | ||||
-rw-r--r-- | coverage/tomlconfig.py | 8 | ||||
-rw-r--r-- | coverage/types.py | 10 |
5 files changed, 33 insertions, 28 deletions
diff --git a/coverage/config.py b/coverage/config.py index 04bde26f..8ab68741 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -18,7 +18,9 @@ from typing import ( from coverage.exceptions import ConfigError from coverage.misc import isolate_module, human_sorted_items, substitute_variables from coverage.tomlconfig import TomlConfigParser, TomlDecodeError -from coverage.types import TConfigurable, TConfigSection, TConfigValue +from coverage.types import ( + TConfigurable, TConfigSectionIn, TConfigValueIn, TConfigSectionOut, TConfigValueOut, +) os = isolate_module(os) @@ -71,9 +73,9 @@ class HandyConfigParser(configparser.ConfigParser): return super().options(real_section) raise ConfigError(f"No section: {section!r}") - def get_section(self, section: str) -> TConfigSection: + def get_section(self, section: str) -> TConfigSectionOut: """Get the contents of a section, as a dictionary.""" - d: Dict[str, TConfigValue] = {} + d: Dict[str, TConfigValueOut] = {} for opt in self.options(section): d[opt] = self.get(section, opt) return d @@ -249,7 +251,7 @@ class CoverageConfig(TConfigurable): self.paths: Dict[str, List[str]] = {} # Options for plugins - self.plugin_options: Dict[str, TConfigSection] = {} + self.plugin_options: Dict[str, TConfigSectionOut] = {} MUST_BE_LIST = { "debug", "concurrency", "plugins", @@ -257,7 +259,7 @@ class CoverageConfig(TConfigurable): "run_omit", "run_include", } - def from_args(self, **kwargs: TConfigValue) -> None: + def from_args(self, **kwargs: TConfigValueIn) -> None: """Read config values from `kwargs`.""" for k, v in kwargs.items(): if v is not None: @@ -441,11 +443,11 @@ class CoverageConfig(TConfigurable): return True return False - def get_plugin_options(self, plugin: str) -> TConfigSection: + def get_plugin_options(self, plugin: str) -> TConfigSectionOut: """Get a dictionary of options for the plugin named `plugin`.""" return self.plugin_options.get(plugin, {}) - def set_option(self, option_name: str, value: Union[TConfigValue, TConfigSection]) -> None: + def set_option(self, option_name: str, value: Union[TConfigValueIn, TConfigSectionIn]) -> None: """Set an option in the configuration. `option_name` is a colon-separated string indicating the section and @@ -476,7 +478,7 @@ class CoverageConfig(TConfigurable): # If we get here, we didn't find the option. raise ConfigError(f"No such option: {option_name!r}") - def get_option(self, option_name: str) -> Optional[TConfigValue]: + def get_option(self, option_name: str) -> Optional[TConfigValueOut]: """Get an option from the configuration. `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, def read_coverage_config( config_file: Union[bool, str], warn: Callable[[str], None], - **kwargs: TConfigValue, + **kwargs: TConfigValueIn, ) -> CoverageConfig: """Read the coverage.py configuration. diff --git a/coverage/control.py b/coverage/control.py index acd89b94..4e97ce9c 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -47,7 +47,8 @@ from coverage.report import render_report from coverage.results import Analysis from coverage.summary import SummaryReporter from coverage.types import ( - TConfigurable, TConfigSection, TConfigValue, TFileDisposition, TLineNo, TMorf, + TConfigurable, TConfigSectionIn, TConfigValueIn, TConfigValueOut, + TFileDisposition, TLineNo, TMorf, ) from coverage.xmlreport import XmlReporter @@ -55,7 +56,7 @@ from coverage.xmlreport import XmlReporter os = isolate_module(os) @contextlib.contextmanager -def override_config(cov: Coverage, **kwargs: TConfigValue) -> Generator[None, None, None]: +def override_config(cov: Coverage, **kwargs: TConfigValueIn) -> Generator[None, None, None]: """Temporarily tweak the configuration of `cov`. The arguments are applied to `cov.config` with the `from_args` method. @@ -120,12 +121,12 @@ class Coverage(TConfigurable): timid: Optional[bool]=None, branch: Optional[bool]=None, config_file: Union[str, bool]=True, - source: Optional[List[str]]=None, - source_pkgs: Optional[List[str]]=None, - omit: Optional[Union[str, List[str]]]=None, - include: Optional[Union[str, List[str]]]=None, - debug: Optional[List[str]]=None, - concurrency: Optional[Union[str, List[str]]]=None, + source: Optional[Iterable[str]]=None, + source_pkgs: Optional[Iterable[str]]=None, + omit: Optional[Union[str, Iterable[str]]]=None, + include: Optional[Union[str, Iterable[str]]]=None, + debug: Optional[Iterable[str]]=None, + concurrency: Optional[Union[str, Iterable[str]]]=None, check_preimported: bool=False, context: Optional[str]=None, messages: bool=False, @@ -425,7 +426,7 @@ class Coverage(TConfigurable): if self._messages: print(msg) - def get_option(self, option_name: str) -> Optional[TConfigValue]: + def get_option(self, option_name: str) -> Optional[TConfigValueOut]: """Get an option from the configuration. `option_name` is a colon-separated string indicating the section and @@ -443,7 +444,7 @@ class Coverage(TConfigurable): """ return self.config.get_option(option_name) - def set_option(self, option_name: str, value: Union[TConfigValue, TConfigSection]) -> None: + def set_option(self, option_name: str, value: Union[TConfigValueIn, TConfigSectionIn]) -> None: """Set an option in the configuration. `option_name` is a colon-separated string indicating the section and diff --git a/coverage/files.py b/coverage/files.py index 2aca85ed..e2800bf2 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -351,7 +351,7 @@ def _glob_to_regex(pattern: str) -> str: def globs_to_regex( patterns: Iterable[str], case_insensitive: bool=False, - partial: bool=False + partial: bool=False, ) -> re.Pattern[str]: """Convert glob patterns to a compiled regex that matches any of them. diff --git a/coverage/tomlconfig.py b/coverage/tomlconfig.py index 737c728c..3b8ff347 100644 --- a/coverage/tomlconfig.py +++ b/coverage/tomlconfig.py @@ -11,7 +11,7 @@ from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type, T from coverage import env from coverage.exceptions import ConfigError from coverage.misc import import_third_party, substitute_variables -from coverage.types import TConfigSection, TConfigValue +from coverage.types import TConfigSectionOut, TConfigValueOut if env.PYVERSION >= (3, 11, 0, "alpha", 7): @@ -65,7 +65,7 @@ class TomlConfigParser: raise ConfigError(msg.format(filename)) return [] - def _get_section(self, section: str) -> Tuple[Optional[str], Optional[TConfigSection]]: + def _get_section(self, section: str) -> Tuple[Optional[str], Optional[TConfigSectionOut]]: """Get a section from the data. Arguments: @@ -92,7 +92,7 @@ class TomlConfigParser: return None, None return real_section, data - def _get(self, section: str, option: str) -> Tuple[str, TConfigValue]: + def _get(self, section: str, option: str) -> Tuple[str, TConfigValueOut]: """Like .get, but returns the real section name and the value.""" name, data = self._get_section(section) if data is None: @@ -135,7 +135,7 @@ class TomlConfigParser: raise ConfigError(f"No section: {section!r}") return list(data.keys()) - def get_section(self, section: str) -> TConfigSection: + def get_section(self, section: str) -> TConfigSectionOut: _, data = self._get_section(section) return data or {} diff --git a/coverage/types.py b/coverage/types.py index ed22e699..8ec4f37a 100644 --- a/coverage/types.py +++ b/coverage/types.py @@ -107,14 +107,16 @@ TCovKwargs = Any ## Configuration # One value read from a config file. -TConfigValue = Optional[Union[bool, int, float, str, List[str]]] +TConfigValueIn = Optional[Union[bool, int, float, str, Iterable[str]]] +TConfigValueOut = Optional[Union[bool, int, float, str, List[str]]] # An entire config section, mapping option names to values. -TConfigSection = Mapping[str, TConfigValue] +TConfigSectionIn = Mapping[str, TConfigValueIn] +TConfigSectionOut = Mapping[str, TConfigValueOut] class TConfigurable(Protocol): """Something that can proxy to the coverage configuration settings.""" - def get_option(self, option_name: str) -> Optional[TConfigValue]: + def get_option(self, option_name: str) -> Optional[TConfigValueOut]: """Get an option from the configuration. `option_name` is a colon-separated string indicating the section and @@ -125,7 +127,7 @@ class TConfigurable(Protocol): """ - def set_option(self, option_name: str, value: Union[TConfigValue, TConfigSection]) -> None: + def set_option(self, option_name: str, value: Union[TConfigValueIn, TConfigSectionIn]) -> None: """Set an option in the configuration. `option_name` is a colon-separated string indicating the section and |