Skip to content

Commit 1f0926e

Browse files
authored
Merge branch 'dev' into middleware_chaining
2 parents c9e2360 + bd11d48 commit 1f0926e

File tree

9 files changed

+44
-19
lines changed

9 files changed

+44
-19
lines changed

azure/functions/_abc.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ def message(self) -> str:
4747
pass
4848

4949

50+
class WarmUpContext(abc.ABC):
51+
"""Warmup context object."""
52+
pass
53+
54+
5055
class TraceContext(abc.ABC):
5156
"""Trace context object."""
5257

@@ -126,6 +131,12 @@ def retry_context(self) -> RetryContext:
126131
"""Context for retries to the function."""
127132
pass
128133

134+
@property
135+
@abc.abstractmethod
136+
def warmup_context(self) -> WarmUpContext:
137+
"""Context for warmup to the function."""
138+
pass
139+
129140

130141
class HttpRequest(abc.ABC):
131142
"""HTTP request object."""

azure/functions/_eventhub.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class EventHubEvent(func_abc.EventHubEvent):
1313

1414
def __init__(self, *,
1515
body: bytes,
16-
trigger_metadata: typing.Mapping[str, meta.Datum] = None,
16+
trigger_metadata: typing.Optional[
17+
typing.Mapping[str, meta.Datum]] = None,
1718
enqueued_time: typing.Optional[datetime.datetime] = None,
1819
partition_key: typing.Optional[str] = None,
1920
sequence_number: typing.Optional[int] = None,

azure/functions/_http.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ class HttpResponse(_abc.HttpResponse):
6666
"""
6767

6868
def __init__(self,
69-
body: typing.Union[str, bytes] = None, *,
70-
status_code: int = None,
69+
body: typing.Optional[typing.Union[str, bytes]] = None, *,
70+
status_code: typing.Optional[int] = None,
7171
headers: typing.Optional[typing.Mapping[str, str]] = None,
7272
mimetype: typing.Optional[str] = None,
73-
charset: str = None) -> None:
73+
charset: typing.Optional[str] = None) -> None:
7474
if status_code is None:
7575
status_code = 200
7676
self.__status_code = status_code

azure/functions/decorators/generic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class GenericInputBinding(InputBinding):
1010

1111
@staticmethod
12-
def get_binding_name() -> str:
12+
def get_binding_name():
1313
pass
1414

1515
def __init__(self,
@@ -23,7 +23,7 @@ def __init__(self,
2323
class GenericOutputBinding(OutputBinding):
2424

2525
@staticmethod
26-
def get_binding_name() -> str:
26+
def get_binding_name():
2727
pass
2828

2929
def __init__(self,
@@ -37,7 +37,7 @@ def __init__(self,
3737
class GenericTrigger(Trigger):
3838

3939
@staticmethod
40-
def get_binding_name() -> str:
40+
def get_binding_name():
4141
pass
4242

4343
def __init__(self,

azure/functions/decorators/servicebus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self,
5050

5151
class ServiceBusTopicTrigger(Trigger):
5252
@staticmethod
53-
def get_binding_name():
53+
def get_binding_name() -> str:
5454
return SERVICE_BUS_TRIGGER
5555

5656
def __init__(self,
@@ -74,7 +74,7 @@ def __init__(self,
7474

7575
class ServiceBusTopicOutput(OutputBinding):
7676
@staticmethod
77-
def get_binding_name():
77+
def get_binding_name() -> str:
7878
return SERVICE_BUS
7979

8080
def __init__(self,

azure/functions/kafka.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class KafkaEvent(AbstractKafkaEvent):
1616

1717
def __init__(self, *,
1818
body: bytes,
19-
trigger_metadata: typing.Mapping[str, meta.Datum] = None,
19+
trigger_metadata: typing.Optional[
20+
typing.Mapping[str, meta.Datum]] = None,
2021
key: typing.Optional[str] = None,
2122
offset: typing.Optional[int] = None,
2223
partition: typing.Optional[int] = None,

azure/functions/servicebus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ServiceBusMessage(azf_sbus.ServiceBusMessage):
1616
def __init__(
1717
self, *,
1818
body: bytes,
19-
trigger_metadata: Mapping[str, Any] = None,
19+
trigger_metadata: Optional[Mapping[str, Any]] = None,
2020
content_type: Optional[str] = None,
2121
correlation_id: Optional[str] = None,
2222
dead_letter_source: Optional[str] = None,

tests/test_http_asgi.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import unittest
66

77
import azure.functions as func
8-
from azure.functions._abc import TraceContext, RetryContext
8+
from azure.functions._abc import TraceContext, RetryContext, WarmUpContext
99
from azure.functions._http_asgi import (
1010
AsgiMiddleware
1111
)
@@ -114,15 +114,17 @@ def _generate_func_context(
114114
function_name='httptrigger',
115115
function_directory='/home/roger/wwwroot/httptrigger',
116116
trace_context=TraceContext,
117-
retry_context=RetryContext
117+
retry_context=RetryContext,
118+
warmup_context=WarmUpContext
118119
) -> func.Context:
119120
class MockContext(func.Context):
120-
def __init__(self, ii, fn, fd, tc, rc):
121+
def __init__(self, ii, fn, fd, tc, rc, wc):
121122
self._invocation_id = ii
122123
self._function_name = fn
123124
self._function_directory = fd
124125
self._trace_context = tc
125126
self._retry_context = rc
127+
self._warmup_context = wc
126128

127129
@property
128130
def invocation_id(self):
@@ -144,8 +146,12 @@ def trace_context(self):
144146
def retry_context(self):
145147
return self._retry_context
146148

149+
@property
150+
def warmup_context(self):
151+
return self._warmup_context
152+
147153
return MockContext(invocation_id, function_name, function_directory,
148-
trace_context, retry_context)
154+
trace_context, retry_context, warmup_context)
149155

150156
def test_middleware_calls_app(self):
151157
app = MockAsgiApplication()

tests/test_http_wsgi.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from io import StringIO, BytesIO
66

77
import azure.functions as func
8-
from azure.functions._abc import TraceContext, RetryContext
8+
from azure.functions._abc import TraceContext, RetryContext, WarmUpContext
99
from azure.functions._http import HttpResponseHeaders
1010
from azure.functions._http_wsgi import (
1111
WsgiRequest,
@@ -223,15 +223,17 @@ def _generate_func_context(
223223
function_name='httptrigger',
224224
function_directory='/home/roger/wwwroot/httptrigger',
225225
trace_context=TraceContext,
226-
retry_context=RetryContext
226+
retry_context=RetryContext,
227+
warmup_context=WarmUpContext
227228
) -> func.Context:
228229
class MockContext(func.Context):
229-
def __init__(self, ii, fn, fd, tc, rc):
230+
def __init__(self, ii, fn, fd, tc, rc, wc):
230231
self._invocation_id = ii
231232
self._function_name = fn
232233
self._function_directory = fd
233234
self._trace_context = tc
234235
self._retry_context = rc
236+
self._warmup_context = wc
235237

236238
@property
237239
def invocation_id(self):
@@ -253,8 +255,12 @@ def trace_context(self):
253255
def retry_context(self):
254256
return self._retry_context
255257

258+
@property
259+
def warmup_context(self):
260+
return self._warmup_context
261+
256262
return MockContext(invocation_id, function_name, function_directory,
257-
trace_context, retry_context)
263+
trace_context, retry_context, warmup_context)
258264

259265
def _generate_wsgi_app(self,
260266
status='200 OK',

0 commit comments

Comments
 (0)