ruff: Fix UP006 Use list instead of List for type annotation.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-07-11 17:30:17 -07:00
committed by Tim Abbott
parent c2214b3904
commit e08a24e47f
457 changed files with 3588 additions and 3857 deletions

View File

@@ -4,7 +4,7 @@ import os
import re
import unicodedata
from datetime import datetime
from typing import IO, Any, BinaryIO, Callable, Iterator, List, Optional, Tuple, Union
from typing import IO, Any, BinaryIO, Callable, Iterator, Optional, Union
from urllib.parse import unquote, urljoin
from django.conf import settings
@@ -65,7 +65,7 @@ def create_attachment(
notify_attachment_update(user_profile, "add", attachment.to_dict())
def get_file_info(user_file: UploadedFile) -> Tuple[str, str]:
def get_file_info(user_file: UploadedFile) -> tuple[str, str]:
uploaded_file_name = user_file.name
assert uploaded_file_name is not None
@@ -191,11 +191,11 @@ def delete_message_attachment(path_id: str) -> bool:
return upload_backend.delete_message_attachment(path_id)
def delete_message_attachments(path_ids: List[str]) -> None:
def delete_message_attachments(path_ids: list[str]) -> None:
return upload_backend.delete_message_attachments(path_ids)
def all_message_attachments() -> Iterator[Tuple[str, datetime]]:
def all_message_attachments() -> Iterator[tuple[str, datetime]]:
return upload_backend.all_message_attachments()
@@ -377,7 +377,7 @@ def upload_emoji_image(
def get_emoji_file_content(
session: OutgoingSession, emoji_url: str, emoji_id: int, logger: logging.Logger
) -> Tuple[bytes, str]: # nocoverage
) -> tuple[bytes, str]: # nocoverage
original_emoji_url = emoji_url + ".original"
logger.info("Downloading %s", original_emoji_url)

View File

@@ -1,6 +1,6 @@
import os
from datetime import datetime
from typing import IO, Any, BinaryIO, Callable, Iterator, List, Optional, Tuple
from typing import IO, Any, BinaryIO, Callable, Iterator, Optional
from zerver.models import Realm, UserProfile
@@ -49,18 +49,18 @@ class ZulipUploadBackend:
def delete_message_attachment(self, path_id: str) -> bool:
raise NotImplementedError
def delete_message_attachments(self, path_ids: List[str]) -> None:
def delete_message_attachments(self, path_ids: list[str]) -> None:
for path_id in path_ids:
self.delete_message_attachment(path_id)
def all_message_attachments(self) -> Iterator[Tuple[str, datetime]]:
def all_message_attachments(self) -> Iterator[tuple[str, datetime]]:
raise NotImplementedError
# Avatar image uploads
def get_avatar_url(self, hash_key: str, medium: bool = False) -> str:
raise NotImplementedError
def get_avatar_contents(self, file_path: str) -> Tuple[bytes, str]:
def get_avatar_contents(self, file_path: str) -> tuple[bytes, str]:
raise NotImplementedError
def get_avatar_path(self, hash_key: str, medium: bool = False) -> str:

View File

@@ -4,7 +4,7 @@ import random
import secrets
import shutil
from datetime import datetime
from typing import IO, Any, BinaryIO, Callable, Iterator, Literal, Optional, Tuple
from typing import IO, Any, BinaryIO, Callable, Iterator, Literal, Optional
from django.conf import settings
from typing_extensions import override
@@ -95,7 +95,7 @@ class LocalUploadBackend(ZulipUploadBackend):
return delete_local_file("files", path_id)
@override
def all_message_attachments(self) -> Iterator[Tuple[str, datetime]]:
def all_message_attachments(self) -> Iterator[tuple[str, datetime]]:
assert settings.LOCAL_UPLOADS_DIR is not None
for dirname, _, files in os.walk(settings.LOCAL_UPLOADS_DIR + "/files"):
for f in files:
@@ -110,7 +110,7 @@ class LocalUploadBackend(ZulipUploadBackend):
return "/user_avatars/" + self.get_avatar_path(hash_key, medium)
@override
def get_avatar_contents(self, file_path: str) -> Tuple[bytes, str]:
def get_avatar_contents(self, file_path: str) -> tuple[bytes, str]:
image_data = read_local_file("avatars", file_path + ".original")
content_type = guess_type(file_path)[0]
return image_data, content_type or "application/octet-stream"

View File

@@ -2,7 +2,7 @@ import logging
import os
import secrets
from datetime import datetime
from typing import IO, Any, BinaryIO, Callable, Dict, Iterator, List, Literal, Optional, Tuple
from typing import IO, Any, BinaryIO, Callable, Iterator, Literal, Optional
from urllib.parse import urljoin, urlsplit, urlunsplit
import boto3
@@ -75,7 +75,7 @@ def upload_image_to_s3(
"STANDARD_IA",
] = "STANDARD",
cache_control: Optional[str] = None,
extra_metadata: Optional[Dict[str, str]] = None,
extra_metadata: Optional[dict[str, str]] = None,
) -> None:
key = bucket.Object(file_name)
metadata = {
@@ -233,13 +233,13 @@ class S3UploadBackend(ZulipUploadBackend):
return self.delete_file_from_s3(path_id, self.uploads_bucket)
@override
def delete_message_attachments(self, path_ids: List[str]) -> None:
def delete_message_attachments(self, path_ids: list[str]) -> None:
self.uploads_bucket.delete_objects(
Delete={"Objects": [{"Key": path_id} for path_id in path_ids]}
)
@override
def all_message_attachments(self) -> Iterator[Tuple[str, datetime]]:
def all_message_attachments(self) -> Iterator[tuple[str, datetime]]:
client = self.uploads_bucket.meta.client
paginator = client.get_paginator("list_objects_v2")
page_iterator = paginator.paginate(Bucket=self.uploads_bucket.name)
@@ -257,7 +257,7 @@ class S3UploadBackend(ZulipUploadBackend):
return self.get_public_upload_url(self.get_avatar_path(hash_key, medium))
@override
def get_avatar_contents(self, file_path: str) -> Tuple[bytes, str]:
def get_avatar_contents(self, file_path: str) -> tuple[bytes, str]:
key = self.avatar_bucket.Object(file_path + ".original")
image_data = key.get()["Body"].read()
content_type = key.content_type