Skip to content

Commit 40c105b

Browse files
committed
added back support for returning None
1 parent 3baa53b commit 40c105b

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

azure_functions_worker/bindings/datumdef.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ def datum_as_proto(datum: Datum) -> protos.TypedData:
197197
enable_content_negotiation=False,
198198
body=datum_as_proto(datum.value['body']),
199199
))
200+
elif datum.type is None:
201+
return None
200202
else:
201203
raise NotImplementedError(
202204
'unexpected Datum type: {!r}'.format(datum.type)

azure_functions_worker/bindings/generic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def encode(cls, obj: Any, *,
2828

2929
elif isinstance(obj, (bytes, bytearray)):
3030
return datumdef.Datum(type='bytes', value=bytes(obj))
31+
elif obj is None:
32+
return datumdef.Datum(type=None, value=obj)
3133
else:
3234
raise NotImplementedError
3335

@@ -45,6 +47,8 @@ def decode(cls, data: datumdef.Datum, *, trigger_metadata) -> typing.Any:
4547
result = data.value
4648
elif data_type == 'json':
4749
result = data.value
50+
elif data_type is None:
51+
result = None
4852
else:
4953
raise ValueError(
5054
f'unexpected type of data received for the "generic" binding '

azure_functions_worker/bindings/meta.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,8 @@ def to_outgoing_param_binding(binding: str, obj: typing.Any, *,
178178
rpc_shared_memory=shared_mem_value)
179179
else:
180180
# If not, send it as part of the response message over RPC
181+
# rpc_val can be None here as we now support a None return type
181182
rpc_val = datumdef.datum_as_proto(datum)
182-
if rpc_val is None:
183-
raise TypeError('Cannot convert datum to rpc_val')
184183
return protos.ParameterBinding(
185184
name=out_name,
186185
data=rpc_val)

tests/unittests/generic_functions/foobar_nil_data/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@
33
import logging
44

55

6-
def main(input):
6+
def main(input) -> None:
77
logging.info("Hello World")
8-
# The function must return a non-None value
9-
return "This is fine"

tests/unittests/test_mock_generic_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,4 @@ async def test_mock_generic_as_nil_data(self):
222222
protos.StatusResult.Success)
223223
self.assertEqual(
224224
r.response.return_value,
225-
protos.TypedData(string="This is fine"))
225+
protos.TypedData())

0 commit comments

Comments
 (0)