Skip to content

Commit 02ca3f4

Browse files
committed
Use named parameters for client c'tor
Due to the new key parameter, we want to be more explicit Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent dbee19b commit 02ca3f4

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
## Upgrading
88

99
* An API key for authorization must now be passed to the `DispatchClient`.
10+
* The client constructor now requires named parameters. If you are using the client directly, you will need to update your code to use named parameters.
1011

1112
## New Features
1213

src/frequenz/client/dispatch/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
DEFAULT_DISPATCH_API_PORT = 50051
3737

3838

39-
def get_client(host: str, port: int, key: str) -> Client:
39+
def get_client(*, host: str, port: int, key: str) -> Client:
4040
"""Get a new client instance.
4141
4242
Args:
@@ -48,7 +48,7 @@ def get_client(host: str, port: int, key: str) -> Client:
4848
Client: A new client instance.
4949
"""
5050
channel = grpc.aio.insecure_channel(f"{host}:{port}")
51-
return Client(channel, f"{host}:{port}", key)
51+
return Client(grpc_channel=channel, svc_addr=f"{host}:{port}", key=key)
5252

5353

5454
# Click command groups
@@ -82,7 +82,7 @@ async def cli(ctx: click.Context, host: str, port: int, key: str) -> None:
8282
if ctx.obj is None:
8383
ctx.obj = {}
8484

85-
ctx.obj["client"] = get_client(host, port, key)
85+
ctx.obj["client"] = get_client(host=host, port=port, key=key)
8686
ctx.obj["params"] = {
8787
"host": host,
8888
"port": port,

src/frequenz/client/dispatch/_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
class Client:
3737
"""Dispatch API client."""
3838

39-
def __init__(self, grpc_channel: grpc.aio.Channel, svc_addr: str, key: str) -> None:
39+
def __init__(
40+
self, *, grpc_channel: grpc.aio.Channel, svc_addr: str, key: str
41+
) -> None:
4042
"""Initialize the client.
4143
4244
Args:
@@ -66,7 +68,7 @@ async def list(
6668
6769
```python
6870
grpc_channel = grpc.aio.insecure_channel("example")
69-
client = Client(grpc_channel, "localhost:50051", "key")
71+
client = Client(grpc_channel=grpc_channel, svc_addr="localhost:50051", key="key")
7072
async for dispatch in client.list(microgrid_id=1):
7173
print(dispatch)
7274
```

src/frequenz/client/dispatch/test/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(
2626
Args:
2727
shuffle_after_create: Whether to shuffle the dispatches after creating them.
2828
"""
29-
super().__init__(MagicMock(), "mock", "all")
29+
super().__init__(grpc_channel=MagicMock(), svc_addr="mock", key="all")
3030
self._stub = FakeService() # type: ignore
3131
self._service._shuffle_after_create = shuffle_after_create
3232

0 commit comments

Comments
 (0)