Skip to content

Commit 55c08eb

Browse files
chore: fix mypy errors from stricter type checking in new version
Update RedisClientProtocol.delete to use variadic *names parameter matching the actual redis-py signature. Add casts for _init_client returns and type annotation for _regex_cache. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7d41c93 commit 55c08eb

4 files changed

Lines changed: 17 additions & 14 deletions

File tree

aws_lambda_powertools/utilities/data_masking/provider/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from collections.abc import Callable
1212

1313
PRESERVE_CHARS = set("-_. ")
14-
_regex_cache = {}
14+
_regex_cache: dict[str, re.Pattern[str]] = {}
1515

1616
JSON_DUMPS_CALL = functools.partial(json.dumps, ensure_ascii=False)
1717

aws_lambda_powertools/utilities/idempotency/persistence/redis.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66
from contextlib import contextmanager
77
from datetime import timedelta
8-
from typing import Any, Literal, Protocol
8+
from typing import Any, Literal, Protocol, cast
99

1010
import redis
1111
from typing_extensions import TypeAlias, deprecated
@@ -76,7 +76,7 @@ def set( # noqa
7676
) -> bool | None:
7777
raise NotImplementedError
7878

79-
def delete(self, keys: bytes | str | memoryview) -> Any:
79+
def delete(self, *names: bytes | str | memoryview) -> Any:
8080
raise NotImplementedError
8181

8282

@@ -185,22 +185,25 @@ def _init_client(self) -> RedisClientProtocol:
185185
try:
186186
if self.url:
187187
logger.debug(f"Using URL format to connect to Cache: {self.host}")
188-
return client.from_url(url=self.url)
188+
return cast(RedisClientProtocol, client.from_url(url=self.url))
189189
else:
190190
# Cache in cluster mode doesn't support db parameter
191191
extra_param_connection: dict[str, Any] = {}
192192
if self.mode != "cluster":
193193
extra_param_connection = {"db": self.db_index}
194194

195195
logger.debug(f"Using arguments to connect to Cache: {self.host}")
196-
return client(
197-
host=self.host,
198-
port=self.port,
199-
username=self.username,
200-
password=self.password,
201-
decode_responses=True,
202-
ssl=self.ssl,
203-
**extra_param_connection,
196+
return cast(
197+
RedisClientProtocol,
198+
client(
199+
host=self.host,
200+
port=self.port,
201+
username=self.username,
202+
password=self.password,
203+
decode_responses=True,
204+
ssl=self.ssl,
205+
**extra_param_connection,
206+
),
204207
)
205208
except redis.exceptions.ConnectionError as exc:
206209
logger.debug(f"Cannot connect to Cache endpoint: {self.host}")

examples/idempotency/src/getting_started_with_idempotency_redis_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
max_connections=1000,
2222
)
2323

24-
persistence_layer = CachePersistenceLayer(client=client)
24+
persistence_layer = CachePersistenceLayer(client=client) # type: ignore[arg-type]
2525

2626

2727
@dataclass

examples/idempotency/src/using_redis_client_with_local_certs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
ssl_ca_certs=f"{abs_lambda_path()}/certs/cache_ca.pem", # (4)!
2828
)
2929

30-
persistence_layer = CachePersistenceLayer(client=redis_client)
30+
persistence_layer = CachePersistenceLayer(client=redis_client) # type: ignore[arg-type]
3131
config = IdempotencyConfig(
3232
expires_after_seconds=2 * 60, # 2 minutes
3333
)

0 commit comments

Comments
 (0)