-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
124 lines (99 loc) · 2.47 KB
/
api.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from typing import Tuple, Any, Callable
from demo_package.api_versioner import api_version
@api_version(1)
def example_function(a):
"""
Example function API V1
:param a: Input a
:return: Returns all inputs
"""
return a
@api_version(2)
def example_function(a, b):
"""
Example function API V2
:param a: Input a
:param b: Input b
:return: Returns all inputs
"""
return a, b
class ExampleClass:
def __init__(self):
self.var = 5
# methods and static methods
example_method: Callable[[Any, Any, Any], Tuple[Any, Any, Any]]
@api_version(1)
def example_method(self, a):
"""
Example method API V1.
:param a: Input a
:return: Returns all inputs
"""
return a
@api_version(2)
def example_method(self, a, b):
"""
Example method API V2.
:param a: Input a
:param b: Input b
:return: Returns all inputs
"""
return a, b
@api_version(3)
@staticmethod
def example_method(a, b, c):
"""
Example method API V3. This one is a staticmethod
:param a: Input a
:param b: Input b
:param c: Input c
:return: Returns all inputs
"""
return a, b, c
# method and property
@api_version(1)
def example_attr(self):
"""
Example attribute. The future API versions change this to a property
"""
return self.var
@api_version(2)
@property
def example_attr(self):
"""
Example property. This property does not have a setter
"""
return self.var
@api_version(3)
@property
def example_attr(self):
"""
Example property API V3. This is a property getter
Returns the var attribute
"""
return self.var
@example_attr.setter
def example_attr(self, example_attr):
"""
Setter method for the API V3 property.
"""
self.var = example_attr
# Class method
example_classmethod: Callable[[Any], "ExampleClass"]
@api_version(1)
@classmethod
def example_classmethod(cls):
"""
Example class method
:return: Instance of this class
"""
return cls()
@api_version(2)
@classmethod
def example_classmethod(cls, a):
"""
Example class method
:param a: Input a
:return: Instance of this class
"""
return cls()