Skip to content

Commit

Permalink
Update code to black 2024 style
Browse files Browse the repository at this point in the history
  • Loading branch information
bisho committed Mar 5, 2024
1 parent f053288 commit b8720cb
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
ignore=E203,W503
ignore=E203,W503,E704,E701
max-line-length = 88
select = B,B9,BLK,C,E,F,I,S,W
max-complexity = 10
Expand Down
6 changes: 2 additions & 4 deletions src/meta_memcache/base/base_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class BaseSerializer(ABC):
def serialize(
self,
value: Any,
) -> EncodedValue:
...
) -> EncodedValue: ...

@abstractmethod
def unserialize(self, data: Blob, encoding_id: int) -> Any:
...
def unserialize(self, data: Blob, encoding_id: int) -> Any: ...
14 changes: 6 additions & 8 deletions src/meta_memcache/commands/high_level_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,19 @@ def _get(
lease_policy: Optional[LeasePolicy] = None,
recache_policy: Optional[RecachePolicy] = None,
return_cas_token: bool = False,
) -> Optional[Value]:
... # pragma: no cover
) -> Optional[Value]: ... # pragma: no cover

def _process_get_result(
self, key: Union[Key, str], result: ReadResponse
) -> Optional[Value]:
... # pragma: no cover
) -> Optional[Value]: ... # pragma: no cover

def _get_typed_value(
self,
key: Union[Key, str],
value: Any,
cls: Type[T],
error_on_type_mismatch: bool = False,
) -> Optional[T]:
... # pragma: no cover
) -> Optional[T]: ... # pragma: no cover

def _get_delta_flags(
self,
Expand All @@ -67,8 +64,9 @@ def _get_delta_flags(
no_reply: bool = False,
cas_token: Optional[int] = None,
return_value: bool = False,
) -> Tuple[Set[Flag], Dict[IntFlag, int], Dict[TokenFlag, bytes]]:
... # pragma: no cover
) -> Tuple[
Set[Flag], Dict[IntFlag, int], Dict[TokenFlag, bytes]
]: ... # pragma: no cover


class HighLevelCommandsMixin:
Expand Down
6 changes: 2 additions & 4 deletions src/meta_memcache/connection/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@


class ConnectionPoolProvider(Protocol):
def get_pool(self, key: Key) -> ConnectionPool:
... # pragma: no cover
def get_pool(self, key: Key) -> ConnectionPool: ... # pragma: no cover

def get_counters(self) -> Dict[ServerAddress, PoolCounters]:
... # pragma: no cover
def get_counters(self) -> Dict[ServerAddress, PoolCounters]: ... # pragma: no cover


class HostConnectionPoolProvider:
Expand Down
3 changes: 1 addition & 2 deletions src/meta_memcache/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ def __init__(self, server: str, message: str) -> None:
super().__init__(message)


class ServerMarkedDownError(MemcacheServerError):
...
class ServerMarkedDownError(MemcacheServerError): ...
11 changes: 5 additions & 6 deletions src/meta_memcache/interfaces/cache_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

class CacheApi(CommandsProtocol, Protocol):
@property
def on_write_failure(self) -> WriteFailureEvent:
... # pragma: no cover
def on_write_failure(self) -> WriteFailureEvent: ... # pragma: no cover

@on_write_failure.setter
def on_write_failure(self, value: WriteFailureEvent) -> None:
... # pragma: no cover
def on_write_failure(
self, value: WriteFailureEvent
) -> None: ... # pragma: no cover

def get_counters(self) -> Dict[ServerAddress, PoolCounters]:
... # pragma: no cover
def get_counters(self) -> Dict[ServerAddress, PoolCounters]: ... # pragma: no cover
8 changes: 4 additions & 4 deletions src/meta_memcache/interfaces/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def exec_multi_on_pool(
... # pragma: no cover

@property
def on_write_failure(self) -> WriteFailureEvent:
... # pragma: no cover
def on_write_failure(self) -> WriteFailureEvent: ... # pragma: no cover

@on_write_failure.setter
def on_write_failure(self, value: WriteFailureEvent) -> None:
... # pragma: no cover
def on_write_failure(
self, value: WriteFailureEvent
) -> None: ... # pragma: no cover
45 changes: 15 additions & 30 deletions src/meta_memcache/interfaces/high_level_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def set(
cas_token: Optional[int] = None,
stale_policy: Optional[StalePolicy] = None,
set_mode: SetMode = SetMode.SET,
) -> bool:
... # pragma: no cover
) -> bool: ... # pragma: no cover

def refill(
self,
Expand Down Expand Up @@ -76,59 +75,52 @@ def touch(
key: Union[Key, str],
ttl: int,
no_reply: bool = False,
) -> bool:
... # pragma: no cover
) -> bool: ... # pragma: no cover

def get_or_lease(
self,
key: Union[Key, str],
lease_policy: LeasePolicy,
touch_ttl: Optional[int] = None,
recache_policy: Optional[RecachePolicy] = None,
) -> Optional[Any]:
... # pragma: no cover
) -> Optional[Any]: ... # pragma: no cover

def get_or_lease_cas(
self,
key: Union[Key, str],
lease_policy: LeasePolicy,
touch_ttl: Optional[int] = None,
recache_policy: Optional[RecachePolicy] = None,
) -> Tuple[Optional[Any], Optional[int]]:
... # pragma: no cover
) -> Tuple[Optional[Any], Optional[int]]: ... # pragma: no cover

def get(
self,
key: Union[Key, str],
touch_ttl: Optional[int] = None,
recache_policy: Optional[RecachePolicy] = None,
) -> Optional[Any]:
... # pragma: no cover
) -> Optional[Any]: ... # pragma: no cover

def multi_get(
self,
keys: Iterable[Union[Key, str]],
touch_ttl: Optional[int] = None,
recache_policy: Optional[RecachePolicy] = None,
) -> Dict[Key, Optional[Any]]:
... # pragma: no cover
) -> Dict[Key, Optional[Any]]: ... # pragma: no cover

def _multi_get(
self,
keys: Iterable[Union[Key, str]],
touch_ttl: Optional[int] = None,
recache_policy: Optional[RecachePolicy] = None,
return_cas_token: bool = False,
) -> Dict[Key, Optional[Value]]:
... # pragma: no cover
) -> Dict[Key, Optional[Value]]: ... # pragma: no cover

def get_cas(
self,
key: Union[Key, str],
touch_ttl: Optional[int] = None,
recache_policy: Optional[RecachePolicy] = None,
) -> Tuple[Optional[Any], Optional[int]]:
... # pragma: no cover
) -> Tuple[Optional[Any], Optional[int]]: ... # pragma: no cover

def _get(
self,
Expand All @@ -137,8 +129,7 @@ def _get(
lease_policy: Optional[LeasePolicy] = None,
recache_policy: Optional[RecachePolicy] = None,
return_cas_token: bool = False,
) -> Optional[Value]:
... # pragma: no cover
) -> Optional[Value]: ... # pragma: no cover

def get_typed(
self,
Expand All @@ -147,8 +138,7 @@ def get_typed(
touch_ttl: Optional[int] = None,
recache_policy: Optional[RecachePolicy] = None,
error_on_type_mismatch: bool = False,
) -> Optional[T]:
... # pragma: no cover
) -> Optional[T]: ... # pragma: no cover

def get_cas_typed(
self,
Expand All @@ -157,8 +147,7 @@ def get_cas_typed(
touch_ttl: Optional[int] = None,
recache_policy: Optional[RecachePolicy] = None,
error_on_type_mismatch: bool = False,
) -> Tuple[Optional[T], Optional[int]]:
... # pragma: no cover
) -> Tuple[Optional[T], Optional[int]]: ... # pragma: no cover

def delta(
self,
Expand All @@ -167,8 +156,7 @@ def delta(
refresh_ttl: Optional[int] = None,
no_reply: bool = False,
cas_token: Optional[int] = None,
) -> bool:
... # pragma: no cover
) -> bool: ... # pragma: no cover

def delta_initialize(
self,
Expand All @@ -179,17 +167,15 @@ def delta_initialize(
refresh_ttl: Optional[int] = None,
no_reply: bool = False,
cas_token: Optional[int] = None,
) -> bool:
... # pragma: no cover
) -> bool: ... # pragma: no cover

def delta_and_get(
self,
key: Union[Key, str],
delta: int,
refresh_ttl: Optional[int] = None,
cas_token: Optional[int] = None,
) -> Optional[int]:
... # pragma: no cover
) -> Optional[int]: ... # pragma: no cover

def delta_initialize_and_get(
self,
Expand All @@ -199,5 +185,4 @@ def delta_initialize_and_get(
initial_ttl: int,
refresh_ttl: Optional[int] = None,
cas_token: Optional[int] = None,
) -> Optional[int]:
... # pragma: no cover
) -> Optional[int]: ... # pragma: no cover
15 changes: 5 additions & 10 deletions src/meta_memcache/interfaces/meta_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def meta_multiget(
int_flags: Optional[Dict[IntFlag, int]] = None,
token_flags: Optional[Dict[TokenFlag, bytes]] = None,
failure_handling: FailureHandling = DEFAULT_FAILURE_HANDLING,
) -> Dict[Key, ReadResponse]:
... # pragma: no cover
) -> Dict[Key, ReadResponse]: ... # pragma: no cover

def meta_get(
self,
Expand All @@ -29,8 +28,7 @@ def meta_get(
int_flags: Optional[Dict[IntFlag, int]] = None,
token_flags: Optional[Dict[TokenFlag, bytes]] = None,
failure_handling: FailureHandling = DEFAULT_FAILURE_HANDLING,
) -> ReadResponse:
... # pragma: no cover
) -> ReadResponse: ... # pragma: no cover

def meta_set(
self,
Expand All @@ -41,8 +39,7 @@ def meta_set(
int_flags: Optional[Dict[IntFlag, int]] = None,
token_flags: Optional[Dict[TokenFlag, bytes]] = None,
failure_handling: FailureHandling = DEFAULT_FAILURE_HANDLING,
) -> WriteResponse:
... # pragma: no cover
) -> WriteResponse: ... # pragma: no cover

def meta_delete(
self,
Expand All @@ -51,8 +48,7 @@ def meta_delete(
int_flags: Optional[Dict[IntFlag, int]] = None,
token_flags: Optional[Dict[TokenFlag, bytes]] = None,
failure_handling: FailureHandling = DEFAULT_FAILURE_HANDLING,
) -> WriteResponse:
... # pragma: no cover
) -> WriteResponse: ... # pragma: no cover

def meta_arithmetic(
self,
Expand All @@ -61,5 +57,4 @@ def meta_arithmetic(
int_flags: Optional[Dict[IntFlag, int]] = None,
token_flags: Optional[Dict[TokenFlag, bytes]] = None,
failure_handling: FailureHandling = DEFAULT_FAILURE_HANDLING,
) -> WriteResponse:
... # pragma: no cover
) -> WriteResponse: ... # pragma: no cover
9 changes: 3 additions & 6 deletions src/meta_memcache/interfaces/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,11 @@ def exec_multi(
... # pragma: no cover

@property
def executor(self) -> Executor:
... # pragma: no cover
def executor(self) -> Executor: ... # pragma: no cover

def get_counters(self) -> Dict[ServerAddress, PoolCounters]:
... # pragma: no cover
def get_counters(self) -> Dict[ServerAddress, PoolCounters]: ... # pragma: no cover


class HasRouter(Protocol):
@property
def router(self) -> Router:
... # pragma: no cover
def router(self) -> Router: ... # pragma: no cover
12 changes: 4 additions & 8 deletions src/meta_memcache/metrics/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,23 @@ def init_metrics(
metrics: List[MetricDefinition],
gauges: List[MetricDefinition],
namespace: str = "",
) -> None:
... # pragma: no cover
) -> None: ... # pragma: no cover

@abstractmethod
def metric_inc(
self,
key: str,
value: Union[float, int] = 1,
labels: Optional[Dict[str, str]] = None,
) -> None:
... # pragma: no cover
) -> None: ... # pragma: no cover

@abstractmethod
def gauge_set(
self,
key: str,
value: float,
labels: Optional[Dict[str, str]] = None,
) -> None:
... # pragma: no cover
) -> None: ... # pragma: no cover

@abstractmethod
def get_counters(self) -> Dict[str, float]:
... # pragma: no cover
def get_counters(self) -> Dict[str, float]: ... # pragma: no cover
6 changes: 3 additions & 3 deletions src/meta_memcache/routers/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ def _exec_multi_prepare_pool_map(
) -> Dict[ConnectionPool, List[Tuple[Key, MaybeValue]]]:
if values is not None and len(values) != len(keys):
raise ValueError("Values, if provided, needs to match the number of keys")
pool_map: DefaultDict[
ConnectionPool, List[Tuple[Key, MaybeValue]]
] = defaultdict(list)
pool_map: DefaultDict[ConnectionPool, List[Tuple[Key, MaybeValue]]] = (
defaultdict(list)
)
for i, key in enumerate(keys):
pool_map[pool_getter(key)].append((key, values[i] if values else None))
return pool_map
Expand Down

0 comments on commit b8720cb

Please sign in to comment.