Skip to content

Commit 02c43d4

Browse files
committed
fix more typing
1 parent 502c108 commit 02c43d4

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

api/import_export/export.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
import typing
55
from collections.abc import Iterator
66
from dataclasses import dataclass
7+
from typing import TYPE_CHECKING
78

89
import boto3
10+
11+
if TYPE_CHECKING:
12+
from mypy_boto3_s3.client import S3Client
913
from django.core import serializers
1014
from django.core.serializers.json import DjangoJSONEncoder
1115
from django.db.models import F, Model, Q
@@ -54,8 +58,8 @@
5458

5559

5660
class S3OrganisationExporter:
57-
def __init__(self, s3_client: typing.Any = None) -> None:
58-
self.s3_client = s3_client or boto3.client("s3")
61+
def __init__(self, s3_client: "S3Client | None" = None) -> None:
62+
self.s3_client: "S3Client" = s3_client or boto3.client("s3")
5963

6064
def export_to_s3(
6165
self,

api/import_export/utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
import logging
33
import typing
44

5+
if typing.TYPE_CHECKING:
6+
from mypy_boto3_s3.client import S3Client
7+
from mypy_boto3_s3.type_defs import CompletedPartTypeDef
8+
59
logger = logging.getLogger(__name__)
610

711

@@ -19,15 +23,15 @@ class S3MultipartUploadWriter:
1923

2024
def __init__(
2125
self,
22-
s3_client: typing.Any,
26+
s3_client: "S3Client",
2327
bucket_name: str,
2428
key: str,
2529
) -> None:
2630
self._s3_client = s3_client
2731
self._bucket_name = bucket_name
2832
self._key = key
2933
self._buffer = io.BytesIO()
30-
self._parts: list[dict[str, typing.Any]] = []
34+
self._parts: list[CompletedPartTypeDef] = []
3135
self._part_number = 1
3236
self._upload_id: str | None = None
3337

@@ -61,6 +65,7 @@ def __exit__(
6165
if self._buffer.tell() > 0:
6266
self._upload_part()
6367

68+
assert self._upload_id
6469
# Complete the multipart upload
6570
self._s3_client.complete_multipart_upload(
6671
Bucket=self._bucket_name,
@@ -76,6 +81,7 @@ def write(self, data: bytes) -> None:
7681
self._upload_part()
7782

7883
def _upload_part(self) -> None:
84+
assert self._upload_id
7985
self._buffer.seek(0)
8086
response = self._s3_client.upload_part(
8187
Bucket=self._bucket_name,

api/poetry.lock

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ requests-mock = "^1.11.0"
227227
django-extensions = "^3.2.3"
228228
pdbpp = "^0.10.3"
229229
mypy-boto3-dynamodb = "^1.33.0"
230+
mypy-boto3-s3 = "^1.36.0"
230231
pytest-structlog = "^1.1"
231232
pyfakefs = "^5.7.4"
232233
mypy = "^1.15.0"

api/sse/sse_service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ def send_environment_update_message_for_environment(environment): # type: ignor
6161
def stream_access_logs(
6262
timeout_seconds: int = 300,
6363
) -> Generator[SSEAccessLogs, None, None]:
64+
assert settings.AWS_SSE_LOGS_BUCKET_NAME
65+
6466
gpg = gnupg.GPG(gnupghome=GNUPG_HOME)
6567
bucket = boto3.resource("s3").Bucket(settings.AWS_SSE_LOGS_BUCKET_NAME)
6668

api/tests/unit/sse/test_sse_service.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def test_stream_access_logs(mocker: MockerFixture, aws_credentials: None) -> Non
125125

126126
# Next, let's create a bucket
127127
bucket_name = settings.AWS_SSE_LOGS_BUCKET_NAME
128+
assert bucket_name
128129
s3_client = boto3.client("s3", region_name="eu-west-2")
129130
s3_client.create_bucket(
130131
Bucket=bucket_name,

0 commit comments

Comments
 (0)