more mypy coverage

This commit is contained in:
Manuel Barkhau 2019-01-07 18:47:04 +01:00
parent e32448ea8c
commit b7f2eeb091
2 changed files with 133 additions and 8 deletions

View file

@ -147,7 +147,7 @@ OptionVal = typ.Union[str, bool, None]
BOOL_OPTIONS: typ.Mapping[str, OptionVal] = {'commit': False, 'tag': None, 'push': None}
def _parse_cfg(cfg_buffer: typ.TextIO) -> RawConfig:
def _parse_cfg(cfg_buffer: typ.IO[str]) -> RawConfig:
cfg_parser = _ConfigParser()
if hasattr(cfg_parser, 'read_file'):
@ -171,7 +171,7 @@ def _parse_cfg(cfg_buffer: typ.TextIO) -> RawConfig:
return raw_cfg
def _parse_toml(cfg_buffer: typ.TextIO) -> RawConfig:
def _parse_toml(cfg_buffer: typ.IO[str]) -> RawConfig:
raw_full_cfg = toml.load(cfg_buffer)
raw_cfg = raw_full_cfg.get('pycalver', {})
@ -182,10 +182,11 @@ def _parse_toml(cfg_buffer: typ.TextIO) -> RawConfig:
def _normalize_file_patterns(raw_cfg: RawConfig) -> FilePatterns:
version_str = raw_cfg['current_version']
version_pattern = raw_cfg['version_pattern']
pep440_version = version.to_pep440(version_str)
file_patterns = raw_cfg['file_patterns']
version_str : str = raw_cfg['current_version']
version_pattern: str = raw_cfg['version_pattern']
pep440_version : str = version.to_pep440(version_str)
file_patterns: FilePatterns = raw_cfg['file_patterns']
for filepath, patterns in list(file_patterns.items()):
if not os.path.exists(filepath):
@ -216,10 +217,10 @@ def _parse_config(raw_cfg: RawConfig) -> Config:
if 'current_version' not in raw_cfg:
raise ValueError("Missing 'pycalver.current_version'")
version_str = raw_cfg['current_version']
version_str: str = raw_cfg['current_version']
version_str = raw_cfg['current_version'] = version_str.strip("'\" ")
version_pattern = raw_cfg.get('version_pattern', "{pycalver}")
version_pattern: str = raw_cfg.get('version_pattern', "{pycalver}")
version_pattern = raw_cfg['version_pattern'] = version_pattern.strip("'\" ")
# NOTE (mb 2019-01-05): Provoke ValueError if version_pattern
@ -264,6 +265,8 @@ def parse(ctx: ProjectContext) -> MaybeConfig:
log.warning(f"File not found: {ctx.config_filepath}")
return None
fh : typ.IO[str]
try:
with ctx.config_filepath.open(mode="rt", encoding="utf-8") as fh:
if ctx.config_format == 'toml':
@ -428,6 +431,8 @@ def write_content(ctx: ProjectContext) -> None:
# config_format : str
# vcs_type : typ.Optional[str]
fh: typ.IO[str]
cfg_content = default_config(ctx)
if os.path.exists("pyproject.toml"):
with io.open("pyproject.toml", mode="at", encoding="utf-8") as fh: