Skip to content

Commit ce998cf

Browse files
committed
Add type annotations to commands module
1 parent 2923711 commit ce998cf

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

stagpy/commands.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
"""Definition of non-processing subcommands."""
22

3+
from __future__ import annotations
34
from itertools import zip_longest
45
from math import ceil
56
from shutil import get_terminal_size
67
from textwrap import indent, TextWrapper
78
import sys
9+
import typing
810

911
import loam.tools
1012
import pandas
@@ -14,6 +16,12 @@
1416
from .config import CONFIG_FILE, CONFIG_LOCAL
1517
from ._helpers import baredoc
1618

19+
if typing.TYPE_CHECKING:
20+
from typing import (Sequence, Tuple, Optional, Mapping, Callable, Union,
21+
Iterable, Any)
22+
from pathlib import Path
23+
from .datatypes import Varf, Varr, Vart
24+
1725

1826
def info_cmd():
1927
"""Print basic information about StagYY run.
@@ -65,15 +73,16 @@ def info_cmd():
6573
print()
6674

6775

68-
def _pretty_print(key_val, sep=': ', min_col_width=39, text_width=None):
76+
def _pretty_print(key_val: Sequence[Tuple[str, str]], sep: str = ': ',
77+
min_col_width: int = 39, text_width: Optional[int] = None):
6978
"""Print a iterable of key/values.
7079
7180
Args:
72-
key_val (list of (str, str)): the pairs of section names and text.
73-
sep (str): separator between section names and text.
74-
min_col_width (int): minimal acceptable column width
75-
text_width (int): text width to use. If set to None, will try to infer
76-
the size of the terminal.
81+
key_val: the pairs of section names and text.
82+
sep: separator between section names and text.
83+
min_col_width: minimal acceptable column width
84+
text_width: text width to use. If set to None, will try to infer the
85+
size of the terminal.
7786
"""
7887
if text_width is None:
7988
text_width = get_terminal_size().columns
@@ -100,14 +109,15 @@ def _pretty_print(key_val, sep=': ', min_col_width=39, text_width=None):
100109
chunks.append(lines[:isep])
101110
lines = lines[isep:]
102111
chunks.append(lines)
103-
lines = zip_longest(*chunks, fillvalue='')
112+
full_lines = zip_longest(*chunks, fillvalue='')
104113

105114
fmt = '|'.join([f'{{:{colw}}}'] * (ncols - 1))
106115
fmt += '|{}' if ncols > 1 else '{}'
107-
print(*(fmt.format(*line) for line in lines), sep='\n')
116+
print(*(fmt.format(*line) for line in full_lines), sep='\n')
108117

109118

110-
def _layout(dict_vars, dict_vars_extra):
119+
def _layout(dict_vars: Mapping[str, Union[Varf, Varr, Vart]],
120+
dict_vars_extra: Mapping[str, Callable]):
111121
"""Print nicely [(var, description)] from phyvars."""
112122
desc = [(v, m.description) for v, m in dict_vars.items()]
113123
desc.extend((v, baredoc(m)) for v, m in dict_vars_extra.items())
@@ -151,7 +161,8 @@ def version_cmd():
151161
print(f'stagpy version: {__version__}')
152162

153163

154-
def report_parsing_problems(parsing_out):
164+
def report_parsing_problems(
165+
parsing_out: Tuple[Any, Sequence[Path], Sequence[Path]]):
155166
"""Output message about potential parsing problems."""
156167
_, empty, faulty = parsing_out
157168
if CONFIG_FILE in empty or CONFIG_FILE in faulty:
@@ -166,12 +177,11 @@ def report_parsing_problems(parsing_out):
166177
sep='\n', end='\n\n', file=sys.stderr)
167178

168179

169-
def config_pp(subs):
180+
def config_pp(subs: Iterable[str]):
170181
"""Pretty print of configuration options.
171182
172183
Args:
173-
subs (iterable of str): iterable with the list of conf sections to
174-
print.
184+
subs: conf sections to print.
175185
"""
176186
print('(c|f): available only as CLI argument/in the config file',
177187
end='\n\n')

0 commit comments

Comments
 (0)