diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2022-12-29 10:19:14 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2022-12-29 11:28:00 -0500 |
commit | d4c2b18bdd0102ff873514e53ec560c3083c3413 (patch) | |
tree | 4e91bacd91f5a0fbcf4976376bbc87e88d46b551 /coverage/types.py | |
parent | 0accb68cd9ac353bd5464750987e02012bdb8e0c (diff) | |
download | python-coveragepy-git-d4c2b18bdd0102ff873514e53ec560c3083c3413.tar.gz |
mypy: mypy checks plugin.py
Diffstat (limited to 'coverage/types.py')
-rw-r--r-- | coverage/types.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/coverage/types.py b/coverage/types.py new file mode 100644 index 00000000..23c7ef8b --- /dev/null +++ b/coverage/types.py @@ -0,0 +1,47 @@ +# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 +# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt + +""" +Types for use throughout coverage.py. +""" + +from typing import Dict, List, Optional, Tuple, Union, TYPE_CHECKING + +if TYPE_CHECKING: + # Protocol is new in 3.8. PYVERSIONS + from typing import Protocol +else: + class Protocol: # pylint: disable=missing-class-docstring + pass + +# One value read from a config file. +TConfigValue = Union[str, List[str]] +# An entire config section, mapping option names to values. +TConfigSection = Dict[str, TConfigValue] + +class TConfigurable(Protocol): + """Something that can proxy to the coverage configuration settings.""" + + def get_option(self, option_name: str) -> Optional[TConfigValue]: + """Get an option from the configuration. + + `option_name` is a colon-separated string indicating the section and + option name. For example, the ``branch`` option in the ``[run]`` + section of the config file would be indicated with `"run:branch"`. + + Returns the value of the option. + + """ + + def set_option(self, option_name: str, value: Union[TConfigValue, TConfigSection]) -> None: + """Set an option in the configuration. + + `option_name` is a colon-separated string indicating the section and + option name. For example, the ``branch`` option in the ``[run]`` + section of the config file would be indicated with `"run:branch"`. + + `value` is the new value for the option. + + """ + +TArc = Tuple[int, int] |