Skip to content

Commit 53bcc2e

Browse files
committed
pydocs + default val
1 parent a719a91 commit 53bcc2e

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

azure_functions_worker/bindings/meta.py

+29-16
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,31 @@
2525

2626

2727
def load_binding_registry() -> None:
28+
"""
29+
Tries to load azure-functions from the customer's BYO. If it's
30+
not found, it loads the builtin. If the BINDING_REGISTRY is None,
31+
azure-functions hasn't been loaded in properly.
32+
33+
Tries to load the base extension only for python 3.8+.
34+
"""
35+
2836
func = sys.modules.get('azure.functions')
2937

30-
# If fails to acquire customer's BYO azure-functions, load the builtin
3138
if func is None:
3239
import azure.functions as func
3340

3441
global BINDING_REGISTRY
3542
BINDING_REGISTRY = func.get_binding_registry()
3643

3744
if BINDING_REGISTRY is None:
38-
# If the BINDING_REGISTRY is None, azure-functions hasn't been
39-
# loaded in properly.
4045
raise AttributeError('BINDING_REGISTRY is None. azure-functions '
4146
'library not found. Sys Path: %s. '
4247
'Sys Modules: %s. '
4348
'python-packages Path exists: %s.',
4449
sys.path, sys.modules,
4550
os.path.exists(CUSTOMER_PACKAGES_PATH))
4651

47-
# The base extension supports python 3.8+
4852
if sys.version_info.minor >= BASE_EXT_SUPPORTED_PY_MINOR_VERSION:
49-
# Import the base extension
5053
try:
5154
import azurefunctions.extensions.base as clients
5255
global DEFERRED_BINDING_REGISTRY
@@ -62,14 +65,17 @@ def load_binding_registry() -> None:
6265
def get_binding(bind_name: str,
6366
is_deferred_binding: typing.Optional[bool] = False)\
6467
-> object:
68+
"""
69+
First checks if the binding is a non-deferred binding. This is
70+
the most common case.
71+
Second checks if the binding is a deferred binding.
72+
If the binding is neither, it's a generic type.
73+
"""
6574
binding = None
66-
# Common use case
6775
if binding is None and not is_deferred_binding:
6876
binding = BINDING_REGISTRY.get(bind_name)
69-
# Binding is deferred binding
7077
if binding is None and is_deferred_binding:
7178
binding = DEFERRED_BINDING_REGISTRY.get(bind_name)
72-
# Binding is generic
7379
if binding is None:
7480
binding = generic.GenericBinding
7581
return binding
@@ -108,11 +114,11 @@ def has_implicit_output(bind_name: str) -> bool:
108114

109115
def from_incoming_proto(
110116
binding: str,
111-
is_deferred_binding: bool,
112117
pb: protos.ParameterBinding, *,
113118
pytype: typing.Optional[type],
114119
trigger_metadata: typing.Optional[typing.Dict[str, protos.TypedData]],
115-
shmem_mgr: SharedMemoryManager) -> typing.Any:
120+
shmem_mgr: SharedMemoryManager,
121+
is_deferred_binding: typing.Optional[bool] = False) -> typing.Any:
116122
binding = get_binding(binding, is_deferred_binding)
117123
if trigger_metadata:
118124
metadata = {
@@ -239,12 +245,15 @@ def deferred_bindings_decode(binding: typing.Any,
239245
pytype: typing.Optional[type],
240246
datum: typing.Any,
241247
metadata: typing.Any):
242-
# This cache holds deferred binding types (ie. BlobClient, ContainerClient)
243-
# That have already been created, so that the worker can reuse the
244-
# Previously created type without creating a new one.
248+
"""
249+
This cache holds deferred binding types (ie. BlobClient, ContainerClient)
250+
That have already been created, so that the worker can reuse the
251+
Previously created type without creating a new one.
252+
253+
If cache is empty or key doesn't exist, deferred_binding_type is None
254+
"""
245255
global deferred_bindings_cache
246256

247-
# If cache is empty or key doesn't exist, deferred_binding_type is None
248257
if deferred_bindings_cache.get((pb.name,
249258
pytype,
250259
datum.value.content), None) is not None:
@@ -264,8 +273,12 @@ def deferred_bindings_decode(binding: typing.Any,
264273
def check_deferred_bindings_enabled(param_anno: type,
265274
deferred_bindings_enabled: bool) -> (bool,
266275
bool):
267-
# The first bool represents if deferred bindings is enabled at a fx level
268-
# The second represents if the current binding is deferred binding
276+
"""
277+
Checks if deferred bindings is enabled at fx and single binding level
278+
279+
The first bool represents if deferred bindings is enabled at a fx level
280+
The second represents if the current binding is deferred binding
281+
"""
269282
if (DEFERRED_BINDING_REGISTRY is not None
270283
and DEFERRED_BINDING_REGISTRY.check_supported_type(param_anno)):
271284
return True, True

azure_functions_worker/dispatcher.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,11 @@ async def _handle__invocation_request(self, request):
517517

518518
args[pb.name] = bindings.from_incoming_proto(
519519
pb_type_info.binding_name,
520-
pb_type_info.deferred_bindings_enabled,
521520
pb,
522521
trigger_metadata=trigger_metadata,
523522
pytype=pb_type_info.pytype,
524-
shmem_mgr=self._shmem_mgr)
523+
shmem_mgr=self._shmem_mgr,
524+
is_deferred_binding=pb_type_info.deferred_bindings_enabled)
525525

526526
fi_context = self._get_context(invoc_request, fi.name, fi.directory)
527527

azure_functions_worker/loader.py

+5
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ def index_function_app(function_path: str):
248248

249249

250250
def get_fx_raw_bindings(indexed_function, function_info):
251+
"""
252+
If deferred bindings is enabled at the function level,
253+
raw bindings are generated through the base extension.
254+
If not, raw bindings are generated through azure-functions.
255+
"""
251256
if function_info.deferred_bindings_enabled:
252257
return bindings.meta.DEFERRED_BINDING_REGISTRY.get_raw_bindings(
253258
indexed_function, function_info.input_types)

0 commit comments

Comments
 (0)