Skip to content

Commit 575b537

Browse files
author
peterstone2017
committed
comment refactor
1 parent f4fc36e commit 575b537

File tree

5 files changed

+30
-39
lines changed

5 files changed

+30
-39
lines changed

azure/functions/decorators/core.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ def get_binding_name() -> str:
8282

8383
def __init__(self, name: str,
8484
direction: BindingDirection,
85-
data_type: Optional[DataType] = None):
86-
self.type = self.get_binding_name()
85+
data_type: Optional[DataType] = None,
86+
type: Optional[str] = None): # NoQa
87+
self.type = self.get_binding_name() \
88+
if self.get_binding_name() is not None else type
8789
self.name = name
8890
self._direction = direction
8991
self._data_type = data_type
@@ -122,31 +124,36 @@ class Trigger(Binding, ABC, metaclass=ABCBuildDictMeta):
122124
Ref: https://aka.ms/functions-triggers-bindings-overview
123125
"""
124126

125-
def __init__(self, name, data_type) -> None:
127+
def __init__(self, name: str, data_type: Optional[DataType] = None,
128+
type: Optional[str] = None) -> None:
126129
super().__init__(direction=BindingDirection.IN,
127-
name=name, data_type=data_type)
130+
name=name, data_type=data_type, type=type)
128131

129132

130133
class InputBinding(Binding, ABC, metaclass=ABCBuildDictMeta):
131134
"""Class representation of Azure Function Input Binding. \n
132135
Ref: https://aka.ms/functions-triggers-bindings-overview
133136
"""
134137

135-
def __init__(self, name, data_type) -> None:
138+
def __init__(self, name: str, data_type: Optional[DataType] = None,
139+
type: Optional[str] = None) -> None:
136140
super().__init__(direction=BindingDirection.IN,
137-
name=name, data_type=data_type)
141+
name=name, data_type=data_type, type=type)
138142

139143

140144
class OutputBinding(Binding, ABC, metaclass=ABCBuildDictMeta):
141145
"""Class representation of Azure Function Output Binding. \n
142146
Ref: https://aka.ms/functions-triggers-bindings-overview
143147
"""
144148

145-
def __init__(self, name, data_type) -> None:
149+
def __init__(self, name: str, data_type: Optional[DataType] = None,
150+
type: Optional[str] = None) -> None:
146151
super().__init__(direction=BindingDirection.OUT,
147-
name=name, data_type=data_type)
152+
name=name, data_type=data_type, type=type)
148153

149154

150-
def is_supported_trigger_type(trigger: Trigger, trigger_type: Type[Trigger]):
151-
return isinstance(trigger, trigger_type) or \
152-
trigger.get_binding_name() == trigger_type.get_binding_name()
155+
def is_supported_trigger_type(trigger_instance: Trigger,
156+
trigger_type: Type[Trigger]):
157+
return isinstance(trigger_instance,
158+
trigger_type) or \
159+
trigger_instance.type == trigger_type.get_binding_name()

azure/functions/decorators/custom.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,43 @@
77

88

99
class CustomInputBinding(InputBinding):
10-
binding_name: str = ""
1110

1211
@staticmethod
1312
def get_binding_name() -> str:
14-
return CustomInputBinding.binding_name
13+
pass
1514

1615
def __init__(self,
1716
name: str,
1817
type: str,
1918
data_type: Optional[DataType] = None,
2019
**kwargs):
21-
self.type = type
22-
CustomInputBinding.binding_name = type
23-
super().__init__(name=name, data_type=data_type)
20+
super().__init__(name=name, data_type=data_type, type=type)
2421

2522

2623
class CustomOutputBinding(OutputBinding):
27-
binding_name: str = ""
24+
# binding_name: str = ""
2825

2926
@staticmethod
3027
def get_binding_name() -> str:
31-
return CustomOutputBinding.binding_name
28+
pass
3229

3330
def __init__(self,
3431
name: str,
3532
type: str,
3633
data_type: Optional[DataType] = None,
3734
**kwargs):
38-
self.type = type
39-
CustomOutputBinding.binding_name = type
40-
super().__init__(name=name, data_type=data_type)
35+
super().__init__(name=name, data_type=data_type, type=type)
4136

4237

4338
class CustomTrigger(Trigger):
44-
binding_name: str = ""
4539

4640
@staticmethod
4741
def get_binding_name() -> str:
48-
return CustomTrigger.binding_name
42+
pass
4943

5044
def __init__(self,
5145
name: str,
5246
type: str,
5347
data_type: Optional[DataType] = None,
5448
**kwargs):
55-
self.type = type
56-
CustomTrigger.binding_name = type
57-
super().__init__(name=name, data_type=data_type)
49+
super().__init__(name=name, data_type=data_type, type=type)

azure/functions/decorators/function_app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,7 @@ def decorator():
302302

303303
def _add_http_app(self,
304304
http_middleware: Union[AsgiMiddleware, WsgiMiddleware],
305-
app_kwargs: typing.Dict
306-
) -> None:
305+
app_kwargs: typing.Dict) -> None:
307306
"""Add a Wsgi or Asgi app integrated http function.
308307
309308
:param http_middleware: :class:`AsgiMiddleware` or

tests/decorators/test_core.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ def __init__(self,
4545

4646
class TestBindings(unittest.TestCase):
4747
def test_trigger_creation(self):
48-
"""Testing if the trigger creation sets the correct values by default
49-
"""
5048
test_trigger = DummyTrigger(name="dummy", data_type=DataType.UNDEFINED)
5149

5250
expected_dict = {'dataType': DataType.UNDEFINED,
@@ -57,8 +55,6 @@ def test_trigger_creation(self):
5755
self.assertEqual(test_trigger.get_dict_repr(), expected_dict)
5856

5957
def test_param_direction_unset(self):
60-
"""Testing if the trigger creation sets the correct values by default
61-
"""
6258
test_trigger = DummyTrigger(name="dummy", data_type=DataType.UNDEFINED,
6359
direction="dummy", type="hello")
6460

@@ -70,8 +66,6 @@ def test_param_direction_unset(self):
7066
self.assertEqual(test_trigger.get_dict_repr(), expected_dict)
7167

7268
def test_input_creation(self):
73-
"""Testing if the input creation sets the correct values by default
74-
"""
7569
test_input = DummyInputBinding(name="dummy",
7670
data_type=DataType.UNDEFINED)
7771

@@ -84,8 +78,6 @@ def test_input_creation(self):
8478
self.assertEqual(test_input.get_dict_repr(), expected_dict)
8579

8680
def test_output_creation(self):
87-
"""Testing if the output creation sets the correct values by default
88-
"""
8981
test_output = DummyOutputBinding(name="dummy",
9082
data_type=DataType.UNDEFINED)
9183

tests/decorators/test_custom.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def test_custom_trigger_valid_creation(self):
1818
methods=["GET", "POST"],
1919
route="dummy")
2020

21-
self.assertEqual(trigger.get_binding_name(), HTTP_TRIGGER)
21+
self.assertEqual(trigger.get_binding_name(), None)
22+
self.assertEqual(trigger.type, HTTP_TRIGGER)
2223
self.assertEqual(trigger.get_dict_repr(), {
2324
"authLevel": AuthLevel.ANONYMOUS,
2425
"type": HTTP_TRIGGER,
@@ -39,7 +40,7 @@ def test_custom_input_valid_creation(self):
3940
id='dummy_id',
4041
partitionKey='dummy_partitions',
4142
sqlQuery='dummy_query')
42-
self.assertEqual(cosmosdb_input.get_binding_name(), COSMOS_DB)
43+
self.assertEqual(cosmosdb_input.get_binding_name(), None)
4344
self.assertEqual(cosmosdb_input.get_dict_repr(),
4445
{'collectionName': 'dummy_collection',
4546
'connectionStringSetting': 'dummy_str',
@@ -57,7 +58,7 @@ def test_custom_output_valid_creation(self):
5758
path="dummy_path",
5859
connection="dummy_connection")
5960

60-
self.assertEqual(blob_output.get_binding_name(), BLOB)
61+
self.assertEqual(blob_output.get_binding_name(), None)
6162
self.assertEqual(blob_output.get_dict_repr(), {
6263
"type": BLOB,
6364
"direction": BindingDirection.OUT,

0 commit comments

Comments
 (0)