Skip to content

Commit e712bb1

Browse files
committed
chore: ruff it up
1 parent b7d101d commit e712bb1

7 files changed

Lines changed: 74 additions & 55 deletions

File tree

src/aiodynamo/client.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,7 @@ class Client:
374374

375375
def __post_init__(self):
376376
object.__setattr__(
377-
self,
378-
"_metrics",
379-
ClientMetrics.from_telemetry(self.telemetry)
377+
self, "_metrics", ClientMetrics.from_telemetry(self.telemetry)
380378
)
381379

382380
def table(self, name: str) -> Table:
@@ -905,7 +903,9 @@ async def batch_get(
905903
for table, items in response["Responses"].items()
906904
},
907905
unprocessed_keys={
908-
table: [dy2py(key, self.numeric_type) for key in unprocessed["Keys"]]
906+
table: [
907+
dy2py(key, self.numeric_type) for key in unprocessed["Keys"]
908+
]
909909
for table, unprocessed in response["UnprocessedKeys"].items()
910910
},
911911
)
@@ -917,7 +917,9 @@ async def batch_write(
917917
items = request.items()
918918
items_count = sum(len(item.to_request_payload()) for _, item in list(items))
919919

920-
with self.telemetry.tracer.start_as_current_span("dynamodb.batch_write") as span:
920+
with self.telemetry.tracer.start_as_current_span(
921+
"dynamodb.batch_write"
922+
) as span:
921923
span.set_attribute("db.system", "dynamodb")
922924
span.set_attribute("db.operation", "BatchWriteItem")
923925
span.set_attribute("db.batch.item_count", items_count)
@@ -1036,7 +1038,9 @@ async def send_request(
10361038
start = time.perf_counter()
10371039
self._metrics.record_request(operation=action, region=self.region)
10381040

1039-
with self.telemetry.tracer.start_as_current_span(f"dynamodb.{action.lower()}") as span:
1041+
with self.telemetry.tracer.start_as_current_span(
1042+
f"dynamodb.{action.lower()}"
1043+
) as span:
10401044
span.set_attribute("db.system", "dynamodb")
10411045
span.set_attribute("db.operation", action)
10421046

src/aiodynamo/otel/metrics.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class ClientMetrics:
1515
batch_unprocessed_items_total: CounterLike
1616
batch_duration: HistogramLike
1717

18-
1918
@classmethod
2019
def from_telemetry(cls, telemetry: Telemetry) -> "ClientMetrics":
2120
return cls(
@@ -99,7 +98,9 @@ def record_error(self, *, operation: str, region: str, error_type: str) -> None:
9998
},
10099
)
101100

102-
def record_request_duration(self, *, operation: str, region: str, duration: float) -> None:
101+
def record_request_duration(
102+
self, *, operation: str, region: str, duration: float
103+
) -> None:
103104
self.request_duration.record(
104105
duration,
105106
attributes={
@@ -117,7 +118,9 @@ def record_batch_items(self, *, operation: str, region: str, count: int) -> None
117118
},
118119
)
119120

120-
def record_batch_unprocessed_items(self, *, operation: str, region: str, count: int) -> None:
121+
def record_batch_unprocessed_items(
122+
self, *, operation: str, region: str, count: int
123+
) -> None:
121124
self.batch_unprocessed_items_total.add(
122125
count,
123126
attributes={
@@ -126,7 +129,9 @@ def record_batch_unprocessed_items(self, *, operation: str, region: str, count:
126129
},
127130
)
128131

129-
def record_batch_duration(self, *, operation: str, region: str, duration: float) -> None:
132+
def record_batch_duration(
133+
self, *, operation: str, region: str, duration: float
134+
) -> None:
130135
self.batch_duration.record(
131136
duration,
132137
attributes={

src/aiodynamo/otel/types.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,23 @@ def set_attribute(self, name: str, value: Any) -> None: ...
88
def record_exception(self, exception: BaseException) -> None: ...
99

1010
def add_event(
11-
self, name:
12-
str,
13-
attributes: dict[str, Any] | None = None
11+
self, name: str, attributes: dict[str, Any] | None = None
1412
) -> None: ...
1513

1614

1715
class NullSpan:
18-
def set_attribute(self, name: str, value: Any) -> None: pass
19-
def record_exception(self, exception: BaseException) -> None: pass
16+
def set_attribute(self, name: str, value: Any) -> None:
17+
pass
2018

21-
def add_event(
22-
self,
23-
name: str,
24-
attributes: dict[str, Any] | None = None
25-
) -> None: pass
19+
def record_exception(self, exception: BaseException) -> None:
20+
pass
21+
22+
def add_event(self, name: str, attributes: dict[str, Any] | None = None) -> None:
23+
pass
2624

2725

2826
class TracerLike(Protocol):
29-
def start_as_current_span(self, *args, **kwargs) -> ContextManager[Any]:
30-
...
27+
def start_as_current_span(self, *args, **kwargs) -> ContextManager[Any]: ...
3128

3229

3330
class NullTracer(TracerLike):
@@ -38,33 +35,26 @@ def start_as_current_span(self, *args, **kwargs):
3835

3936
class CounterLike(Protocol):
4037
def add(
41-
self,
42-
amount: int | float,
43-
attributes: dict[str, Any] | None = None
38+
self, amount: int | float, attributes: dict[str, Any] | None = None
4439
) -> None: ...
4540

4641

4742
class NoopCounter:
4843
def add(
49-
self,
50-
amount: int | float,
51-
attributes: dict[str, Any] | None = None
52-
) -> None: pass
44+
self, amount: int | float, attributes: dict[str, Any] | None = None
45+
) -> None:
46+
pass
5347

5448

5549
class HistogramLike(Protocol):
5650
def record(
57-
self,
58-
amount: int | float,
59-
attributes: dict[str, Any] | None = None
51+
self, amount: int | float, attributes: dict[str, Any] | None = None
6052
) -> None: ...
6153

6254

6355
class NoopHistogram:
6456
def record(
65-
self,
66-
amount: int | float,
67-
attributes: dict[str, Any] | None = None
57+
self, amount: int | float, attributes: dict[str, Any] | None = None
6858
) -> None:
6959
pass
7060

tests/fakes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def create_histogram(self, name, unit=None, description=None):
3232
self.created[name] = instrument
3333
return instrument
3434

35+
3536
@dataclass
3637
class FakeSpan:
3738
name: str

tests/integration/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,12 @@ def client(
149149
endpoint,
150150
)
151151

152+
152153
@pytest.fixture()
153154
def instrumented_client(
154-
http: HttpImplementation, endpoint: URL, region: str,
155+
http: HttpImplementation,
156+
endpoint: URL,
157+
region: str,
155158
) -> Generator[Client, None, None]:
156159
client = Client(
157160
http,

tests/integration/test_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,9 @@ async def test_attribute_type_filter(client: Client, table: TableName) -> None:
896896

897897

898898
@pytest.mark.asyncio
899-
async def test_batch_write_records_trace_and_metrics(instrumented_client: Client, table: str) -> None:
899+
async def test_batch_write_records_trace_and_metrics(
900+
instrumented_client: Client, table: str
901+
) -> None:
900902
await instrumented_client.batch_write(
901903
{
902904
table: BatchWriteRequest(

tests/unit/test_metrics.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,27 @@ def telemetry():
2828
"record_retry",
2929
{"operation": "Query", "region": "eu-west-1", "reason": "Throttled"},
3030
"aiodynamo.retries",
31-
(1, {"db.operation": "Query", "aws.region": "eu-west-1", "reason": "Throttled"}),
31+
(
32+
1,
33+
{
34+
"db.operation": "Query",
35+
"aws.region": "eu-west-1",
36+
"reason": "Throttled",
37+
},
38+
),
3239
),
3340
(
3441
"record_error",
3542
{"operation": "Scan", "region": "us-east-1", "error_type": "TimeoutError"},
3643
"aiodynamo.errors",
37-
(1, {"db.operation": "Scan", "aws.region": "us-east-1", "error.type": "TimeoutError"}),
44+
(
45+
1,
46+
{
47+
"db.operation": "Scan",
48+
"aws.region": "us-east-1",
49+
"error.type": "TimeoutError",
50+
},
51+
),
3852
),
3953
(
4054
"record_request_duration",
@@ -43,28 +57,28 @@ def telemetry():
4357
(0.25, {"db.operation": "DeleteItem", "aws.region": "us-east-1"}),
4458
),
4559
(
46-
"record_batch_items",
47-
{"operation": "BatchGetItem", "region": "us-east-1", "count": 32},
48-
"aiodynamo.batch.items_total",
49-
(32, {"db.operation": "BatchGetItem", "aws.region": "us-east-1"}),
60+
"record_batch_items",
61+
{"operation": "BatchGetItem", "region": "us-east-1", "count": 32},
62+
"aiodynamo.batch.items_total",
63+
(32, {"db.operation": "BatchGetItem", "aws.region": "us-east-1"}),
5064
),
5165
(
52-
"record_batch_items",
53-
{"operation": "BatchWriteItem", "region": "us-east-1", "count": 1111},
54-
"aiodynamo.batch.items_total",
55-
(1111, {"db.operation": "BatchWriteItem", "aws.region": "us-east-1"}),
66+
"record_batch_items",
67+
{"operation": "BatchWriteItem", "region": "us-east-1", "count": 1111},
68+
"aiodynamo.batch.items_total",
69+
(1111, {"db.operation": "BatchWriteItem", "aws.region": "us-east-1"}),
5670
),
5771
(
58-
"record_batch_unprocessed_items",
59-
{"operation": "BatchWriteItem", "region": "us-east-1", "count": 5},
60-
"aiodynamo.batch.unprocessed_items_total",
61-
(5, {"db.operation": "BatchWriteItem", "aws.region": "us-east-1"}),
72+
"record_batch_unprocessed_items",
73+
{"operation": "BatchWriteItem", "region": "us-east-1", "count": 5},
74+
"aiodynamo.batch.unprocessed_items_total",
75+
(5, {"db.operation": "BatchWriteItem", "aws.region": "us-east-1"}),
6276
),
6377
(
64-
"record_batch_duration",
65-
{"operation": "BatchWriteItem", "region": "us-east-1", "duration": 0.42},
66-
"aiodynamo.batch.duration",
67-
(0.42, {"db.operation": "BatchWriteItem", "aws.region": "us-east-1"}),
78+
"record_batch_duration",
79+
{"operation": "BatchWriteItem", "region": "us-east-1", "duration": 0.42},
80+
"aiodynamo.batch.duration",
81+
(0.42, {"db.operation": "BatchWriteItem", "aws.region": "us-east-1"}),
6882
),
6983
],
7084
)

0 commit comments

Comments
 (0)