Skip to content

Commit f830d9f

Browse files
committed
chore: basic, coarse type hints for all watcher deltas
1 parent b7bf04e commit f830d9f

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

juju/client/overrides.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Copyright 2023 Canonical Ltd.
22
# Licensed under the Apache V2, see LICENCE file for details.
3+
from __future__ import annotations
34

45
import re
5-
from collections import namedtuple
6+
from typing import Any, NamedTuple
67

78
from . import _client, _definitions
89
from .facade import ReturnMapping, Type, TypeEncoder
@@ -22,6 +23,12 @@
2223
]
2324

2425

26+
class _Change(NamedTuple):
27+
entity: str
28+
type: str
29+
data: dict[str, Any]
30+
31+
2532
class Delta(Type):
2633
"""A single websocket delta.
2734
@@ -42,12 +49,11 @@ class Delta(Type):
4249
_toSchema = {"deltas": "deltas"}
4350
_toPy = {"deltas": "deltas"}
4451

45-
def __init__(self, deltas=None):
52+
def __init__(self, deltas: tuple[str, str, dict[str, Any]]):
4653
""":param deltas: [str, str, object]"""
4754
self.deltas = deltas
4855

49-
Change = namedtuple("Change", "entity type data")
50-
change = Change(*self.deltas)
56+
change = _Change(*self.deltas)
5157

5258
self.entity = change.entity
5359
self.type = change.type

juju/delta.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Copyright 2023 Canonical Ltd.
22
# Licensed under the Apache V2, see LICENCE file for details.
3+
from __future__ import annotations
34

4-
from .client import client
5+
from . import model
6+
from .client import client, overrides
57

68

7-
def get_entity_delta(d):
9+
def get_entity_delta(d: overrides.Delta):
810
return _delta_types[d.entity](d.deltas)
911

1012

@@ -13,12 +15,14 @@ def get_entity_class(entity_type):
1315

1416

1517
class EntityDelta(client.Delta):
16-
def get_id(self):
18+
data: dict[str, str]
19+
20+
def get_id(self) -> str:
1721
return self.data["id"]
1822

1923
@classmethod
20-
def get_entity_class(cls):
21-
return None
24+
def get_entity_class(cls) -> type[model.ModelEntity]:
25+
raise NotImplementedError()
2226

2327

2428
class ActionDelta(EntityDelta):

0 commit comments

Comments
 (0)