File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed
Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change 44interface.
55"""
66
7+ from __future__ import annotations
78import pathlib
9+ import typing
810
911from loam .manager import ConfOpt as Conf
1012from loam import tools
1113from loam .tools import switch_opt , command_flag
1214
15+ if typing .TYPE_CHECKING :
16+ from typing import Union , Callable , TypeVar , Tuple
17+ T = TypeVar ('T' )
1318
14- def _slice_or_int (arg ):
19+
20+ def _slice_or_int (arg : str ) -> Union [slice , int ]:
1521 """Parse a string into an integer or slice."""
1622 if ':' in arg :
1723 idxs = arg .split (':' )
1824 if len (idxs ) > 3 :
1925 raise ValueError (f'{ arg } is an invalid slice' )
20- idxs [ 0 ] = int (idxs [0 ]) if idxs [0 ] else None
21- idxs [ 1 ] = int (idxs [1 ]) if idxs [1 ] else None
26+ slice_parts = [ int (idxs [0 ]) if idxs [0 ] else None ,
27+ int (idxs [1 ]) if idxs [1 ] else None ]
2228 if len (idxs ) == 3 :
23- idxs [ 2 ] = int (idxs [2 ]) if idxs [2 ] else None
29+ slice_parts . append ( int (idxs [2 ]) if idxs [2 ] else None )
2430 else :
25- idxs = idxs [ 0 : 2 ] + [ 1 ]
26- return slice (* idxs )
31+ slice_parts . append ( 1 )
32+ return slice (* slice_parts )
2733 return int (arg )
2834
2935
30- def _list_of (from_str ) :
36+ def _list_of (from_str : Callable [[ str ], T ]) -> Callable [[ str ], Tuple [ T ]] :
3137 """Return fn parsing a str as a comma-separated list of given type."""
3238 def parser (arg ):
3339 return tuple (from_str (v ) for v in map (str .strip , arg .split (',' )) if v )
You can’t perform that action at this time.
0 commit comments