Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

upload: Switch from BinaryIO to IO[bytes].

Alex Vandiver2dc737335ee3
diff --git a/zerver/lib/upload/__init__.py b/zerver/lib/upload/__init__.py
index 1a2eb527768..27268487f54 100644
--- a/zerver/lib/upload/__init__.py
+++ b/zerver/lib/upload/__init__.py
@@ -5,7 +5,7 @@ import re
import unicodedata
from collections.abc import Callable, Iterator
from datetime import datetime
-from typing import IO, Any, BinaryIO
+from typing import IO, Any
from urllib.parse import unquote, urljoin
import pyvips
@@ -212,7 +212,7 @@ def attachment_vips_source(path_id: str) -> StreamingSourceWithSize:
return upload_backend.attachment_vips_source(path_id)
-def save_attachment_contents(path_id: str, filehandle: BinaryIO) -> None:
+def save_attachment_contents(path_id: str, filehandle: IO[bytes]) -> None:
return upload_backend.save_attachment_contents(path_id, filehandle)
diff --git a/zerver/lib/upload/base.py b/zerver/lib/upload/base.py
index 021f19420a6..cfc8ec43188 100644
--- a/zerver/lib/upload/base.py
+++ b/zerver/lib/upload/base.py
@@ -2,7 +2,7 @@ import os
from collections.abc import Callable, Iterator
from dataclasses import dataclass
from datetime import datetime
-from typing import IO, Any, BinaryIO
+from typing import IO, Any
import pyvips
@@ -54,7 +54,7 @@ class ZulipUploadBackend:
) -> None:
raise NotImplementedError
- def save_attachment_contents(self, path_id: str, filehandle: BinaryIO) -> None:
+ def save_attachment_contents(self, path_id: str, filehandle: IO[bytes]) -> None:
raise NotImplementedError
def attachment_vips_source(self, path_id: str) -> StreamingSourceWithSize:
diff --git a/zerver/lib/upload/local.py b/zerver/lib/upload/local.py
index 58c5c042f1c..d98d77fc30b 100644
--- a/zerver/lib/upload/local.py
+++ b/zerver/lib/upload/local.py
@@ -5,7 +5,7 @@ import secrets
import shutil
from collections.abc import Callable, Iterator
from datetime import datetime
-from typing import IO, Any, BinaryIO, Literal
+from typing import IO, Any, Literal
import pyvips
from django.conf import settings
@@ -98,7 +98,7 @@ class LocalUploadBackend(ZulipUploadBackend):
write_local_file("files", path_id, file_data)
@override
- def save_attachment_contents(self, path_id: str, filehandle: BinaryIO) -> None:
+ def save_attachment_contents(self, path_id: str, filehandle: IO[bytes]) -> None:
filehandle.write(read_local_file("files", path_id))
@override
diff --git a/zerver/lib/upload/s3.py b/zerver/lib/upload/s3.py
index 29407cff80f..ae3c7bbaefd 100644
--- a/zerver/lib/upload/s3.py
+++ b/zerver/lib/upload/s3.py
@@ -3,7 +3,7 @@ import os
import secrets
from collections.abc import Callable, Iterator
from datetime import datetime
-from typing import IO, TYPE_CHECKING, Any, BinaryIO, Literal
+from typing import IO, TYPE_CHECKING, Any, Literal
from urllib.parse import urljoin, urlsplit, urlunsplit
import botocore
@@ -263,7 +263,7 @@ class S3UploadBackend(ZulipUploadBackend):
)
@override
- def save_attachment_contents(self, path_id: str, filehandle: BinaryIO) -> None:
+ def save_attachment_contents(self, path_id: str, filehandle: IO[bytes]) -> None:
for chunk in self.uploads_bucket.Object(path_id).get()["Body"]:
filehandle.write(chunk)