Skip to content

Commit 6057a61

Browse files
committed
Add type annotations to args module
SUB_CMDS is now a MappingProxyType instead of an OrderedDict
1 parent ce998cf commit 6057a61

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

stagpy/args.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""Parse command line arguments and update :attr:`stagpy.conf`."""
22

3-
from collections import OrderedDict
3+
from __future__ import annotations
44
from inspect import isfunction
5+
from types import MappingProxyType
6+
import typing
57

68
from loam.tools import set_conf_str, create_complete_files
79
from loam.cli import Subcmd, CLIManager
@@ -12,8 +14,11 @@
1214
from ._helpers import baredoc
1315
from .config import CONFIG_DIR
1416

17+
if typing.TYPE_CHECKING:
18+
from typing import Any, Optional, List, Callable
1519

16-
def _sub(cmd, *sections):
20+
21+
def _sub(cmd: Any, *sections: str) -> Subcmd:
1722
"""Build Subcmd instance."""
1823
cmd_func = cmd if isfunction(cmd) else cmd.cmd
1924
return Subcmd(baredoc(cmd), *sections, func=cmd_func)
@@ -25,31 +30,31 @@ def _bare_cmd():
2530
print('Run `stagpy -h` for usage')
2631

2732

28-
SUB_CMDS = OrderedDict((
29-
('common_', Subcmd(doc_module, 'common', func=_bare_cmd)),
30-
('field', _sub(field, 'core', 'plot', 'scaling')),
31-
('rprof', _sub(rprof, 'core', 'plot', 'scaling')),
32-
('time', _sub(time_series, 'core', 'plot', 'scaling')),
33-
('refstate', _sub(refstate, 'core', 'plot')),
34-
('plates', _sub(plates, 'core', 'plot', 'scaling')),
35-
('info', _sub(commands.info_cmd, 'core', 'scaling')),
36-
('var', _sub(commands.var_cmd)),
37-
('version', _sub(commands.version_cmd)),
38-
('config', _sub(commands.config_cmd)),
39-
))
33+
SUB_CMDS = MappingProxyType({
34+
'common_': Subcmd(doc_module, 'common', func=_bare_cmd),
35+
'field': _sub(field, 'core', 'plot', 'scaling'),
36+
'rprof': _sub(rprof, 'core', 'plot', 'scaling'),
37+
'time': _sub(time_series, 'core', 'plot', 'scaling'),
38+
'refstate': _sub(refstate, 'core', 'plot'),
39+
'plates': _sub(plates, 'core', 'plot', 'scaling'),
40+
'info': _sub(commands.info_cmd, 'core', 'scaling'),
41+
'var': _sub(commands.var_cmd),
42+
'version': _sub(commands.version_cmd),
43+
'config': _sub(commands.config_cmd),
44+
})
4045

4146

42-
def parse_args(arglist=None):
47+
def parse_args(arglist: Optional[List[str]] = None) -> Callable[[], None]:
4348
"""Parse cmd line arguments.
4449
4550
Update :attr:`stagpy.conf` accordingly.
4651
4752
Args:
48-
arglist (list of str): the list of cmd line arguments. If set to
49-
None, the arguments are taken from :attr:`sys.argv`.
53+
arglist: the list of cmd line arguments. If set to None, the arguments
54+
are taken from :attr:`sys.argv`.
5055
5156
Returns:
52-
function: the function implementing the sub command to be executed.
57+
the function implementing the sub command to be executed.
5358
"""
5459
climan = CLIManager(conf, **SUB_CMDS)
5560

0 commit comments

Comments
 (0)