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.

zproject: Fix typing errors under the zproject directory.

PIG2082268ac6d0c4e
diff --git a/zproject/backends.py b/zproject/backends.py
index b5251cc3a65..7b42ec7012c 100644
--- a/zproject/backends.py
+++ b/zproject/backends.py
@@ -301,7 +301,7 @@ class ZulipAuthMixin:
"""
name = "undefined"
- _logger = None
+ _logger: Optional[logging.Logger] = None
@property
def logger(self) -> logging.Logger:
diff --git a/zproject/computed_settings.py b/zproject/computed_settings.py
index b8c9facb69f..eadbbca5040 100644
--- a/zproject/computed_settings.py
+++ b/zproject/computed_settings.py
@@ -3,7 +3,6 @@ import sys
import time
import warnings
from copy import deepcopy
-from pathlib import PosixPath
from typing import Any, Dict, List, Tuple, Union
from urllib.parse import urljoin
@@ -165,7 +164,7 @@ ALLOWED_HOSTS += REALM_HOSTS.values()
class TwoFactorLoader(app_directories.Loader):
- def get_dirs(self) -> List[PosixPath]:
+ def get_dirs(self) -> List[Union[bytes, str]]:
dirs = super().get_dirs()
return [d for d in dirs if d.match("two_factor/*")]
diff --git a/zproject/default_settings.py b/zproject/default_settings.py
index ed57d43841a..c4295d5b26e 100644
--- a/zproject/default_settings.py
+++ b/zproject/default_settings.py
@@ -65,7 +65,7 @@ AUTH_LDAP_ALWAYS_UPDATE_USER = False
# Detailed docs in zproject/dev_settings.py.
FAKE_LDAP_MODE: Optional[str] = None
FAKE_LDAP_NUM_USERS = 8
-AUTH_LDAP_ADVANCED_REALM_ACCESS_CONTROL = None
+AUTH_LDAP_ADVANCED_REALM_ACCESS_CONTROL: Optional[Dict[str, Any]] = None
# Social auth; we support providing values for some of these
# settings in zulip-secrets.conf instead of settings.py in development.
@@ -138,8 +138,8 @@ DEFAULT_AVATAR_URI = "/static/images/default-avatar.png"
DEFAULT_LOGO_URI = "/static/images/logo/zulip-org-logo.svg"
S3_AVATAR_BUCKET = ""
S3_AUTH_UPLOADS_BUCKET = ""
-S3_REGION = None
-S3_ENDPOINT_URL = None
+S3_REGION: Optional[str] = None
+S3_ENDPOINT_URL: Optional[str] = None
LOCAL_UPLOADS_DIR: Optional[str] = None
MAX_FILE_UPLOAD_SIZE = 25
diff --git a/zproject/dev_settings.py b/zproject/dev_settings.py
index f5ab55e770f..432d309ae33 100644
--- a/zproject/dev_settings.py
+++ b/zproject/dev_settings.py
@@ -160,7 +160,7 @@ THUMBNAIL_IMAGES = True
SEARCH_PILLS_ENABLED = bool(os.getenv("SEARCH_PILLS_ENABLED", False))
BILLING_ENABLED = True
-LANDING_PAGE_NAVBAR_MESSAGE = None
+LANDING_PAGE_NAVBAR_MESSAGE: Optional[str] = None
# Test custom TOS template rendering
TERMS_OF_SERVICE = "corporate/terms.md"
@@ -175,4 +175,4 @@ USE_X_FORWARDED_PORT = True
# Override the default SAML entity ID
SOCIAL_AUTH_SAML_SP_ENTITY_ID = "http://localhost:9991"
-MEMCACHED_USERNAME = None
+MEMCACHED_USERNAME: Optional[str] = None
diff --git a/zproject/dev_urls.py b/zproject/dev_urls.py
index cb8cea9f9d6..dada1dee88e 100644
--- a/zproject/dev_urls.py
+++ b/zproject/dev_urls.py
@@ -4,7 +4,8 @@ from urllib.parse import urlsplit
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.staticfiles.views import serve as staticfiles_serve
-from django.http import HttpRequest, HttpResponse
+from django.http import HttpRequest
+from django.http.response import FileResponse
from django.urls import path
from django.views.generic import TemplateView
from django.views.static import serve
@@ -110,7 +111,7 @@ if use_prod_static:
]
else:
- def serve_static(request: HttpRequest, path: str) -> HttpResponse:
+ def serve_static(request: HttpRequest, path: str) -> FileResponse:
response = staticfiles_serve(request, path)
response["Access-Control-Allow-Origin"] = "*"
return response
diff --git a/zproject/email_backends.py b/zproject/email_backends.py
index cfdb3a80d66..597f8784a39 100644
--- a/zproject/email_backends.py
+++ b/zproject/email_backends.py
@@ -1,11 +1,13 @@
# https://zulip.readthedocs.io/en/latest/subsystems/email.html#testing-in-a-real-email-client
import configparser
import logging
-from typing import List
+from email.message import Message
+from typing import List, MutableSequence, Union
from django.conf import settings
from django.core.mail import EmailMultiAlternatives
from django.core.mail.backends.smtp import EmailBackend
+from django.core.mail.message import EmailMessage
from django.template import loader
@@ -34,7 +36,7 @@ class EmailLogBackEnd(EmailBackend):
@staticmethod
def log_email(email: EmailMultiAlternatives) -> None:
"""Used in development to record sent emails in a nice HTML log"""
- html_message = "Missing HTML message"
+ html_message: Union[bytes, EmailMessage, Message, str] = "Missing HTML message"
if len(email.alternatives) > 0:
html_message = email.alternatives[0][0]
@@ -68,12 +70,14 @@ class EmailLogBackEnd(EmailBackend):
for email_message in email_messages:
html_alternative = list(email_message.alternatives[0])
+ assert isinstance(html_alternative[0], str)
# Here, we replace the email addresses used in development
# with chat.zulip.org, so that web email providers like Gmail
# will be able to fetch the illustrations used in the emails.
html_alternative[0] = html_alternative[0].replace(
localhost_email_images_base_uri, czo_email_images_base_uri
)
+ assert isinstance(email_message.alternatives, MutableSequence)
email_message.alternatives[0] = tuple(html_alternative)
email_message.to = [get_forward_address()]
diff --git a/zproject/test_extra_settings.py b/zproject/test_extra_settings.py
index 360e88f31c3..d1cc7b771b3 100644
--- a/zproject/test_extra_settings.py
+++ b/zproject/test_extra_settings.py
@@ -1,5 +1,5 @@
import os
-from typing import Dict, List, Tuple
+from typing import Dict, List, Optional, Tuple
import ldap
from django_auth_ldap.config import LDAPSearch
@@ -215,7 +215,7 @@ BIG_BLUE_BUTTON_URL = "https://bbb.example.com/bigbluebutton/"
# By default two factor authentication is disabled in tests.
# Explicitly set this to True within tests that must have this on.
TWO_FACTOR_AUTHENTICATION_ENABLED = False
-PUSH_NOTIFICATION_BOUNCER_URL = None
+PUSH_NOTIFICATION_BOUNCER_URL: Optional[str] = None
THUMBNAIL_IMAGES = True
@@ -269,4 +269,4 @@ RATE_LIMITING_RULES: Dict[str, List[Tuple[int, int]]] = {
"password_reset_form_by_email": [],
}
-FREE_TRIAL_DAYS = None
+FREE_TRIAL_DAYS: Optional[int] = None
diff --git a/zproject/urls.py b/zproject/urls.py
index 9b66e431249..1bd59631cf8 100644
--- a/zproject/urls.py
+++ b/zproject/urls.py
@@ -1,4 +1,5 @@
import os
+from typing import List, Union
from django.conf import settings
from django.conf.urls import include
@@ -10,6 +11,7 @@ from django.contrib.auth.views import (
PasswordResetDoneView,
)
from django.urls import path
+from django.urls.resolvers import URLPattern, URLResolver
from django.utils.module_loading import import_string
from django.views.generic import RedirectView, TemplateView
@@ -634,7 +636,7 @@ i18n_urls = [
]
# Make a copy of i18n_urls so that they appear without prefix for english
-urls = list(i18n_urls)
+urls: List[Union[URLPattern, URLResolver]] = list(i18n_urls)
# Include the dual-use patterns twice
urls += [