Skip to content

Commit dabb050

Browse files
committed
chore: make mypy happy again
1 parent 1ff7ea3 commit dabb050

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/sentry/hybridcloud/apigateway_async/circuitbreaker.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import asyncio
44
import time
55
from collections import defaultdict
6+
from typing import Any
67

78
from django.conf import settings
89

@@ -18,7 +19,7 @@ class CircuitBreaker:
1819
"_counter_idx",
1920
]
2021

21-
def __init__(self, concurrency, failures):
22+
def __init__(self, concurrency: int, failures: tuple[int, int]) -> None:
2223
self.concurrency = concurrency
2324
self.counter_window = failures[0]
2425
self.failures = failures[1]
@@ -27,7 +28,7 @@ def __init__(self, concurrency, failures):
2728
self._counters = [0, 0]
2829
self._counter_idx = 0
2930

30-
def _counter_flip(self, clock):
31+
def _counter_flip(self, clock: int) -> None:
3132
self._clock = clock
3233
prev = self._counter_idx
3334
self._counter_idx = 1 - prev
@@ -40,7 +41,7 @@ def _maybe_counter_flip(self):
4041
if delta // self.counter_window:
4142
self._counter_flip(now)
4243

43-
def counter_incr(self):
44+
def counter_incr(self) -> None:
4445
self._maybe_counter_flip()
4546
self._counters[self._counter_idx] += 1
4647

@@ -66,10 +67,10 @@ class CircuitBreakerCtx:
6667
def __init__(self, cb: CircuitBreaker):
6768
self.cb = cb
6869

69-
def incr_failures(self):
70+
def incr_failures(self) -> None:
7071
self.cb.counter_incr()
7172

72-
async def __aenter__(self):
73+
async def __aenter__(self) -> CircuitBreakerCtx:
7374
if self.cb.overflow():
7475
raise CircuitBreakerOverflow
7576
await self.cb.semaphore.acquire()
@@ -78,7 +79,7 @@ async def __aenter__(self):
7879
raise CircuitBreakerWindowOverflow
7980
return self
8081

81-
async def __aexit__(self, exc_type, exc_value, exc_tb):
82+
async def __aexit__(self, exc_type: Any, exc_value: Any, exc_tb: Any) -> None:
8283
self.cb.semaphore.release()
8384

8485

@@ -94,7 +95,9 @@ def __init__(
9495
concurrency = max_concurrency or settings.APIGATEWAY_PROXY_MAX_CONCURRENCY
9596
failures = failures or settings.APIGATEWAY_PROXY_MAX_FAILURES
9697
failure_window = failure_window or settings.APIGATEWAY_PROXY_FAILURE_WINDOW
97-
self.objs = defaultdict(lambda: CircuitBreaker(concurrency, (failure_window, failures)))
98+
self.objs: dict[str, CircuitBreaker] = defaultdict(
99+
lambda: CircuitBreaker(concurrency, (failure_window, failures))
100+
)
98101

99102
def get(self, key: str) -> CircuitBreakerCtx:
100103
return self.objs[key].ctx()

src/sentry/objectstore/endpoints/organization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from rest_framework.request import Request
1313
from rest_framework.response import Response
1414

15-
from sentry.utils.http import BodyAsyncWrapper, BodyWithLength, BodyWithLengthAiter
15+
from sentry.utils.http import BodyAsyncWrapper, BodyWithLength
1616

1717
# TODO(granian): Remove this and related code paths when we fully switch from uwsgi to granian
1818
uwsgi: Any = None
@@ -153,7 +153,7 @@ def stream_generator():
153153

154154
def get_raw_body_async(
155155
request: HttpRequest,
156-
) -> BodyAsyncWrapper | ChunkedEncodingAsyncDecoder | BodyWithLengthAiter | None:
156+
) -> BodyAsyncWrapper | ChunkedEncodingAsyncDecoder | BodyWithLength:
157157
if request.body:
158158
return BodyAsyncWrapper(request.body)
159159

0 commit comments

Comments
 (0)