-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathbase.py
80 lines (66 loc) · 1.24 KB
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from typing import (
Tuple,
Optional,
Callable,
List,
Union,
Dict
)
from numpy import ndarray
from stock_pandas.common import (
period_to_int
)
ReturnType = Tuple[ndarray, int]
CommandFormula = Callable[..., ReturnType]
CommandArg = Union[str, int, float]
CommandArgs = List[
Union[
Tuple[
Optional[CommandArg],
Optional[Callable[..., CommandArg]]
],
CommandArg
]
]
class CommandPreset:
__slots__ = (
'formula',
'args'
)
formula: CommandFormula
args: CommandArgs
def __init__(
self,
formula: CommandFormula,
args: CommandArgs
) -> None:
self.formula = formula
self.args = args
SubCommandsMap = Optional[
Dict[
str,
CommandPreset
]
]
AliasesMap = Optional[
Dict[
str,
Optional[str]
]
]
COMMANDS: Dict[
str,
Tuple[
Optional[CommandPreset],
SubCommandsMap,
AliasesMap
]
] = {}
arg_period = (
# Default value for the first argument,
# `None` indicates that it is not an optional argument
None,
# Validator and setter for the first argument.
# The function could throw
period_to_int
)