/
casting.py
59 lines (38 loc) · 1.45 KB
/
casting.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
"""Data type hook."""
from typing import Any
from tackle import BaseHook, Field
class IntegerHook(BaseHook):
"""Hook for casting a variable to an integer type."""
hook_name = 'int'
input: Any = Field(..., description="Any variable input.", render_by_default=True)
args: list = ['input']
def exec(self) -> int:
return int(self.input)
class FloatHook(BaseHook):
"""Hook for casting a variable to a float type."""
hook_name = 'float'
input: Any = Field(..., description="Any variable input.", render_by_default=True)
args: list = ['input']
def exec(self) -> float:
return float(self.input)
class BoolHook(BaseHook):
"""Hook for casting a variable to a bool type."""
hook_name = 'bool'
input: Any = Field(..., description="Any variable input.", render_by_default=True)
args: list = ['input']
def exec(self) -> bool:
return bool(self.input)
class StrHook(BaseHook):
"""Hook for casting a variable to a string type."""
hook_name = 'str'
input: Any = Field(..., description="Any variable input.", render_by_default=True)
args: list = ['input']
def exec(self) -> str:
return str(self.input)
class HexHook(BaseHook):
"""Hook for changing an int to a hexidecimal."""
hook_name = 'hex'
input: int = Field(..., description="Any variable input.", render_by_default=True)
args: list = ['input']
def exec(self) -> hex:
return hex(self.input)