Skip to content

Commit 927ed8c

Browse files
authored
refactor: use more sensible type hints (#37)
1 parent 9627049 commit 927ed8c

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

scw_serverless/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Callable, List, Optional, Union
1+
from typing import Any, Callable, Optional, Union
22

33
try:
44
from typing import Unpack
@@ -29,7 +29,7 @@ def __init__(
2929
secret: Optional[dict[str, Any]] = None,
3030
gateway_domains: Optional[list[str]] = None,
3131
):
32-
self.functions: List[Function] = []
32+
self.functions: list[Function] = []
3333
self.service_name: str = service_name
3434
self.gateway_domains: list[str] = gateway_domains if gateway_domains else []
3535
self.env = env
@@ -96,7 +96,7 @@ def handler(event, context)
9696
if "triggers" in kwargs and kwargs["triggers"]:
9797
kwargs["triggers"].append(schedule)
9898
else:
99-
kwargs |= {"triggers": [schedule]}
99+
kwargs["triggers"] = [schedule]
100100
return self.func(**kwargs)
101101

102102
def get(self, url: str, **kwargs: Unpack[FunctionKwargs]) -> Callable:

scw_serverless/config/function.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import sys
22
from dataclasses import dataclass, field
3-
from typing import Callable, List, Literal, Optional, TypedDict
3+
from typing import Callable, Literal, Optional, TypedDict
44

55
import scaleway.function.v1beta1 as sdk
66

7-
try:
8-
from typing import NotRequired
9-
except ImportError:
10-
from typing_extensions import NotRequired
11-
# pylint: disable=wrong-import-position # Conditional import considered a statement
127
from scw_serverless.config.route import GatewayRoute, HTTPMethod
138
from scw_serverless.logger import get_logger
149
from scw_serverless.triggers import Trigger
@@ -31,7 +26,7 @@ def _get_current_runtime() -> sdk.FunctionRuntime:
3126
return runtime
3227

3328

34-
class FunctionKwargs(TypedDict):
29+
class FunctionKwargs(TypedDict, total=False):
3530
"""Typed arguments supported by Scaleway functions.
3631
3732
.. note::
@@ -54,21 +49,21 @@ class FunctionKwargs(TypedDict):
5449
https://developers.scaleway.com/en/products/functions/api/#create-a-function
5550
"""
5651

57-
env: NotRequired[dict[str, str]]
58-
secret: NotRequired[dict[str, str]]
59-
min_scale: NotRequired[int]
60-
max_scale: NotRequired[int]
61-
memory_limit: NotRequired[MemoryLimit]
62-
timeout: NotRequired[str]
63-
custom_domains: NotRequired[List[str]]
64-
privacy: NotRequired[Privacy]
65-
description: NotRequired[str]
66-
http_option: NotRequired[HTTPOption]
52+
env: dict[str, str]
53+
secret: dict[str, str]
54+
min_scale: int
55+
max_scale: int
56+
memory_limit: MemoryLimit
57+
timeout: str
58+
custom_domains: list[str]
59+
privacy: Privacy
60+
description: str
61+
http_option: HTTPOption
6762
# Parameters for the Gateway
68-
url: NotRequired[str]
69-
methods: NotRequired[list[HTTPMethod]]
63+
url: str
64+
methods: list[HTTPMethod]
7065
# Triggers
71-
triggers: NotRequired[list[Trigger]]
66+
triggers: list[Trigger]
7267

7368

7469
# pylint: disable=too-many-instance-attributes

0 commit comments

Comments
 (0)