From e0130bfc0d683cb3d70b84c07eea51e8f389a0a5 Mon Sep 17 00:00:00 2001 From: peterstone2017 Date: Thu, 14 Apr 2022 13:54:10 -0500 Subject: [PATCH] comment refactor --- azure/functions/decorators/core.py | 29 ++++++++++++++-------- azure/functions/decorators/custom.py | 22 ++++++---------- azure/functions/decorators/function_app.py | 3 +-- tests/decorators/test_core.py | 8 ------ tests/decorators/test_custom.py | 7 +++--- 5 files changed, 30 insertions(+), 39 deletions(-) diff --git a/azure/functions/decorators/core.py b/azure/functions/decorators/core.py index 5da7f3de..526138a2 100644 --- a/azure/functions/decorators/core.py +++ b/azure/functions/decorators/core.py @@ -82,8 +82,10 @@ def get_binding_name() -> str: def __init__(self, name: str, direction: BindingDirection, - data_type: Optional[DataType] = None): - self.type = self.get_binding_name() + data_type: Optional[DataType] = None, + type: Optional[str] = None): # NoQa + self.type = self.get_binding_name() \ + if self.get_binding_name() is not None else type self.name = name self._direction = direction self._data_type = data_type @@ -122,9 +124,10 @@ class Trigger(Binding, ABC, metaclass=ABCBuildDictMeta): Ref: https://aka.ms/functions-triggers-bindings-overview """ - def __init__(self, name, data_type) -> None: + def __init__(self, name: str, data_type: Optional[DataType] = None, + type: Optional[str] = None) -> None: super().__init__(direction=BindingDirection.IN, - name=name, data_type=data_type) + name=name, data_type=data_type, type=type) class InputBinding(Binding, ABC, metaclass=ABCBuildDictMeta): @@ -132,9 +135,10 @@ class InputBinding(Binding, ABC, metaclass=ABCBuildDictMeta): Ref: https://aka.ms/functions-triggers-bindings-overview """ - def __init__(self, name, data_type) -> None: + def __init__(self, name: str, data_type: Optional[DataType] = None, + type: Optional[str] = None) -> None: super().__init__(direction=BindingDirection.IN, - name=name, data_type=data_type) + name=name, data_type=data_type, type=type) class OutputBinding(Binding, ABC, metaclass=ABCBuildDictMeta): @@ -142,11 +146,14 @@ class OutputBinding(Binding, ABC, metaclass=ABCBuildDictMeta): Ref: https://aka.ms/functions-triggers-bindings-overview """ - def __init__(self, name, data_type) -> None: + def __init__(self, name: str, data_type: Optional[DataType] = None, + type: Optional[str] = None) -> None: super().__init__(direction=BindingDirection.OUT, - name=name, data_type=data_type) + name=name, data_type=data_type, type=type) -def is_supported_trigger_type(trigger: Trigger, trigger_type: Type[Trigger]): - return isinstance(trigger, trigger_type) or \ - trigger.get_binding_name() == trigger_type.get_binding_name() +def is_supported_trigger_type(trigger_instance: Trigger, + trigger_type: Type[Trigger]): + return isinstance(trigger_instance, + trigger_type) or \ + trigger_instance.type == trigger_type.get_binding_name() diff --git a/azure/functions/decorators/custom.py b/azure/functions/decorators/custom.py index 3199df9d..0e7ee0b8 100644 --- a/azure/functions/decorators/custom.py +++ b/azure/functions/decorators/custom.py @@ -7,51 +7,43 @@ class CustomInputBinding(InputBinding): - binding_name: str = "" @staticmethod def get_binding_name() -> str: - return CustomInputBinding.binding_name + pass def __init__(self, name: str, type: str, data_type: Optional[DataType] = None, **kwargs): - self.type = type - CustomInputBinding.binding_name = type - super().__init__(name=name, data_type=data_type) + super().__init__(name=name, data_type=data_type, type=type) class CustomOutputBinding(OutputBinding): - binding_name: str = "" + # binding_name: str = "" @staticmethod def get_binding_name() -> str: - return CustomOutputBinding.binding_name + pass def __init__(self, name: str, type: str, data_type: Optional[DataType] = None, **kwargs): - self.type = type - CustomOutputBinding.binding_name = type - super().__init__(name=name, data_type=data_type) + super().__init__(name=name, data_type=data_type, type=type) class CustomTrigger(Trigger): - binding_name: str = "" @staticmethod def get_binding_name() -> str: - return CustomTrigger.binding_name + pass def __init__(self, name: str, type: str, data_type: Optional[DataType] = None, **kwargs): - self.type = type - CustomTrigger.binding_name = type - super().__init__(name=name, data_type=data_type) + super().__init__(name=name, data_type=data_type, type=type) diff --git a/azure/functions/decorators/function_app.py b/azure/functions/decorators/function_app.py index d15eec95..39e8451b 100644 --- a/azure/functions/decorators/function_app.py +++ b/azure/functions/decorators/function_app.py @@ -302,8 +302,7 @@ def decorator(): def _add_http_app(self, http_middleware: Union[AsgiMiddleware, WsgiMiddleware], - app_kwargs: typing.Dict - ) -> None: + app_kwargs: typing.Dict) -> None: """Add a Wsgi or Asgi app integrated http function. :param http_middleware: :class:`AsgiMiddleware` or diff --git a/tests/decorators/test_core.py b/tests/decorators/test_core.py index c7cb0860..76eedfde 100644 --- a/tests/decorators/test_core.py +++ b/tests/decorators/test_core.py @@ -45,8 +45,6 @@ def __init__(self, class TestBindings(unittest.TestCase): def test_trigger_creation(self): - """Testing if the trigger creation sets the correct values by default - """ test_trigger = DummyTrigger(name="dummy", data_type=DataType.UNDEFINED) expected_dict = {'dataType': DataType.UNDEFINED, @@ -57,8 +55,6 @@ def test_trigger_creation(self): self.assertEqual(test_trigger.get_dict_repr(), expected_dict) def test_param_direction_unset(self): - """Testing if the trigger creation sets the correct values by default - """ test_trigger = DummyTrigger(name="dummy", data_type=DataType.UNDEFINED, direction="dummy", type="hello") @@ -70,8 +66,6 @@ def test_param_direction_unset(self): self.assertEqual(test_trigger.get_dict_repr(), expected_dict) def test_input_creation(self): - """Testing if the input creation sets the correct values by default - """ test_input = DummyInputBinding(name="dummy", data_type=DataType.UNDEFINED) @@ -84,8 +78,6 @@ def test_input_creation(self): self.assertEqual(test_input.get_dict_repr(), expected_dict) def test_output_creation(self): - """Testing if the output creation sets the correct values by default - """ test_output = DummyOutputBinding(name="dummy", data_type=DataType.UNDEFINED) diff --git a/tests/decorators/test_custom.py b/tests/decorators/test_custom.py index 046e4494..249b10f5 100644 --- a/tests/decorators/test_custom.py +++ b/tests/decorators/test_custom.py @@ -18,7 +18,8 @@ def test_custom_trigger_valid_creation(self): methods=["GET", "POST"], route="dummy") - self.assertEqual(trigger.get_binding_name(), HTTP_TRIGGER) + self.assertEqual(trigger.get_binding_name(), None) + self.assertEqual(trigger.type, HTTP_TRIGGER) self.assertEqual(trigger.get_dict_repr(), { "authLevel": AuthLevel.ANONYMOUS, "type": HTTP_TRIGGER, @@ -39,7 +40,7 @@ def test_custom_input_valid_creation(self): id='dummy_id', partitionKey='dummy_partitions', sqlQuery='dummy_query') - self.assertEqual(cosmosdb_input.get_binding_name(), COSMOS_DB) + self.assertEqual(cosmosdb_input.get_binding_name(), None) self.assertEqual(cosmosdb_input.get_dict_repr(), {'collectionName': 'dummy_collection', 'connectionStringSetting': 'dummy_str', @@ -57,7 +58,7 @@ def test_custom_output_valid_creation(self): path="dummy_path", connection="dummy_connection") - self.assertEqual(blob_output.get_binding_name(), BLOB) + self.assertEqual(blob_output.get_binding_name(), None) self.assertEqual(blob_output.get_dict_repr(), { "type": BLOB, "direction": BindingDirection.OUT,