mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	zproject: Fix typing errors under the zproject directory.
This fixes error found with django-stubs and it is a part of #18777. Note that there are various remaining errors that need to be fixed in upstream or elsewhere in our codebase.
This commit is contained in:
		@@ -301,7 +301,7 @@ class ZulipAuthMixin:
 | 
				
			|||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    name = "undefined"
 | 
					    name = "undefined"
 | 
				
			||||||
    _logger = None
 | 
					    _logger: Optional[logging.Logger] = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def logger(self) -> logging.Logger:
 | 
					    def logger(self) -> logging.Logger:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,6 @@ import sys
 | 
				
			|||||||
import time
 | 
					import time
 | 
				
			||||||
import warnings
 | 
					import warnings
 | 
				
			||||||
from copy import deepcopy
 | 
					from copy import deepcopy
 | 
				
			||||||
from pathlib import PosixPath
 | 
					 | 
				
			||||||
from typing import Any, Dict, List, Tuple, Union
 | 
					from typing import Any, Dict, List, Tuple, Union
 | 
				
			||||||
from urllib.parse import urljoin
 | 
					from urllib.parse import urljoin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -165,7 +164,7 @@ ALLOWED_HOSTS += REALM_HOSTS.values()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TwoFactorLoader(app_directories.Loader):
 | 
					class TwoFactorLoader(app_directories.Loader):
 | 
				
			||||||
    def get_dirs(self) -> List[PosixPath]:
 | 
					    def get_dirs(self) -> List[Union[bytes, str]]:
 | 
				
			||||||
        dirs = super().get_dirs()
 | 
					        dirs = super().get_dirs()
 | 
				
			||||||
        return [d for d in dirs if d.match("two_factor/*")]
 | 
					        return [d for d in dirs if d.match("two_factor/*")]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -65,7 +65,7 @@ AUTH_LDAP_ALWAYS_UPDATE_USER = False
 | 
				
			|||||||
# Detailed docs in zproject/dev_settings.py.
 | 
					# Detailed docs in zproject/dev_settings.py.
 | 
				
			||||||
FAKE_LDAP_MODE: Optional[str] = None
 | 
					FAKE_LDAP_MODE: Optional[str] = None
 | 
				
			||||||
FAKE_LDAP_NUM_USERS = 8
 | 
					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
 | 
					# Social auth; we support providing values for some of these
 | 
				
			||||||
# settings in zulip-secrets.conf instead of settings.py in development.
 | 
					# 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"
 | 
					DEFAULT_LOGO_URI = "/static/images/logo/zulip-org-logo.svg"
 | 
				
			||||||
S3_AVATAR_BUCKET = ""
 | 
					S3_AVATAR_BUCKET = ""
 | 
				
			||||||
S3_AUTH_UPLOADS_BUCKET = ""
 | 
					S3_AUTH_UPLOADS_BUCKET = ""
 | 
				
			||||||
S3_REGION = None
 | 
					S3_REGION: Optional[str] = None
 | 
				
			||||||
S3_ENDPOINT_URL = None
 | 
					S3_ENDPOINT_URL: Optional[str] = None
 | 
				
			||||||
LOCAL_UPLOADS_DIR: Optional[str] = None
 | 
					LOCAL_UPLOADS_DIR: Optional[str] = None
 | 
				
			||||||
MAX_FILE_UPLOAD_SIZE = 25
 | 
					MAX_FILE_UPLOAD_SIZE = 25
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -160,7 +160,7 @@ THUMBNAIL_IMAGES = True
 | 
				
			|||||||
SEARCH_PILLS_ENABLED = bool(os.getenv("SEARCH_PILLS_ENABLED", False))
 | 
					SEARCH_PILLS_ENABLED = bool(os.getenv("SEARCH_PILLS_ENABLED", False))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
BILLING_ENABLED = True
 | 
					BILLING_ENABLED = True
 | 
				
			||||||
LANDING_PAGE_NAVBAR_MESSAGE = None
 | 
					LANDING_PAGE_NAVBAR_MESSAGE: Optional[str] = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Test custom TOS template rendering
 | 
					# Test custom TOS template rendering
 | 
				
			||||||
TERMS_OF_SERVICE = "corporate/terms.md"
 | 
					TERMS_OF_SERVICE = "corporate/terms.md"
 | 
				
			||||||
@@ -175,4 +175,4 @@ USE_X_FORWARDED_PORT = True
 | 
				
			|||||||
# Override the default SAML entity ID
 | 
					# Override the default SAML entity ID
 | 
				
			||||||
SOCIAL_AUTH_SAML_SP_ENTITY_ID = "http://localhost:9991"
 | 
					SOCIAL_AUTH_SAML_SP_ENTITY_ID = "http://localhost:9991"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MEMCACHED_USERNAME = None
 | 
					MEMCACHED_USERNAME: Optional[str] = None
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,8 @@ from urllib.parse import urlsplit
 | 
				
			|||||||
from django.conf import settings
 | 
					from django.conf import settings
 | 
				
			||||||
from django.conf.urls.static import static
 | 
					from django.conf.urls.static import static
 | 
				
			||||||
from django.contrib.staticfiles.views import serve as staticfiles_serve
 | 
					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.urls import path
 | 
				
			||||||
from django.views.generic import TemplateView
 | 
					from django.views.generic import TemplateView
 | 
				
			||||||
from django.views.static import serve
 | 
					from django.views.static import serve
 | 
				
			||||||
@@ -110,7 +111,7 @@ if use_prod_static:
 | 
				
			|||||||
    ]
 | 
					    ]
 | 
				
			||||||
else:
 | 
					else:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def serve_static(request: HttpRequest, path: str) -> HttpResponse:
 | 
					    def serve_static(request: HttpRequest, path: str) -> FileResponse:
 | 
				
			||||||
        response = staticfiles_serve(request, path)
 | 
					        response = staticfiles_serve(request, path)
 | 
				
			||||||
        response["Access-Control-Allow-Origin"] = "*"
 | 
					        response["Access-Control-Allow-Origin"] = "*"
 | 
				
			||||||
        return response
 | 
					        return response
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,11 +1,13 @@
 | 
				
			|||||||
# https://zulip.readthedocs.io/en/latest/subsystems/email.html#testing-in-a-real-email-client
 | 
					# https://zulip.readthedocs.io/en/latest/subsystems/email.html#testing-in-a-real-email-client
 | 
				
			||||||
import configparser
 | 
					import configparser
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
from typing import List
 | 
					from email.message import Message
 | 
				
			||||||
 | 
					from typing import List, MutableSequence, Union
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from django.conf import settings
 | 
					from django.conf import settings
 | 
				
			||||||
from django.core.mail import EmailMultiAlternatives
 | 
					from django.core.mail import EmailMultiAlternatives
 | 
				
			||||||
from django.core.mail.backends.smtp import EmailBackend
 | 
					from django.core.mail.backends.smtp import EmailBackend
 | 
				
			||||||
 | 
					from django.core.mail.message import EmailMessage
 | 
				
			||||||
from django.template import loader
 | 
					from django.template import loader
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -34,7 +36,7 @@ class EmailLogBackEnd(EmailBackend):
 | 
				
			|||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
    def log_email(email: EmailMultiAlternatives) -> None:
 | 
					    def log_email(email: EmailMultiAlternatives) -> None:
 | 
				
			||||||
        """Used in development to record sent emails in a nice HTML log"""
 | 
					        """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:
 | 
					        if len(email.alternatives) > 0:
 | 
				
			||||||
            html_message = email.alternatives[0][0]
 | 
					            html_message = email.alternatives[0][0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -68,12 +70,14 @@ class EmailLogBackEnd(EmailBackend):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        for email_message in email_messages:
 | 
					        for email_message in email_messages:
 | 
				
			||||||
            html_alternative = list(email_message.alternatives[0])
 | 
					            html_alternative = list(email_message.alternatives[0])
 | 
				
			||||||
 | 
					            assert isinstance(html_alternative[0], str)
 | 
				
			||||||
            # Here, we replace the email addresses used in development
 | 
					            # Here, we replace the email addresses used in development
 | 
				
			||||||
            # with chat.zulip.org, so that web email providers like Gmail
 | 
					            # with chat.zulip.org, so that web email providers like Gmail
 | 
				
			||||||
            # will be able to fetch the illustrations used in the emails.
 | 
					            # will be able to fetch the illustrations used in the emails.
 | 
				
			||||||
            html_alternative[0] = html_alternative[0].replace(
 | 
					            html_alternative[0] = html_alternative[0].replace(
 | 
				
			||||||
                localhost_email_images_base_uri, czo_email_images_base_uri
 | 
					                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.alternatives[0] = tuple(html_alternative)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            email_message.to = [get_forward_address()]
 | 
					            email_message.to = [get_forward_address()]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
import os
 | 
					import os
 | 
				
			||||||
from typing import Dict, List, Tuple
 | 
					from typing import Dict, List, Optional, Tuple
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import ldap
 | 
					import ldap
 | 
				
			||||||
from django_auth_ldap.config import LDAPSearch
 | 
					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.
 | 
					# By default two factor authentication is disabled in tests.
 | 
				
			||||||
# Explicitly set this to True within tests that must have this on.
 | 
					# Explicitly set this to True within tests that must have this on.
 | 
				
			||||||
TWO_FACTOR_AUTHENTICATION_ENABLED = False
 | 
					TWO_FACTOR_AUTHENTICATION_ENABLED = False
 | 
				
			||||||
PUSH_NOTIFICATION_BOUNCER_URL = None
 | 
					PUSH_NOTIFICATION_BOUNCER_URL: Optional[str] = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
THUMBNAIL_IMAGES = True
 | 
					THUMBNAIL_IMAGES = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -269,4 +269,4 @@ RATE_LIMITING_RULES: Dict[str, List[Tuple[int, int]]] = {
 | 
				
			|||||||
    "password_reset_form_by_email": [],
 | 
					    "password_reset_form_by_email": [],
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FREE_TRIAL_DAYS = None
 | 
					FREE_TRIAL_DAYS: Optional[int] = None
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,5 @@
 | 
				
			|||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					from typing import List, Union
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from django.conf import settings
 | 
					from django.conf import settings
 | 
				
			||||||
from django.conf.urls import include
 | 
					from django.conf.urls import include
 | 
				
			||||||
@@ -10,6 +11,7 @@ from django.contrib.auth.views import (
 | 
				
			|||||||
    PasswordResetDoneView,
 | 
					    PasswordResetDoneView,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
from django.urls import path
 | 
					from django.urls import path
 | 
				
			||||||
 | 
					from django.urls.resolvers import URLPattern, URLResolver
 | 
				
			||||||
from django.utils.module_loading import import_string
 | 
					from django.utils.module_loading import import_string
 | 
				
			||||||
from django.views.generic import RedirectView, TemplateView
 | 
					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
 | 
					# 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
 | 
					# Include the dual-use patterns twice
 | 
				
			||||||
urls += [
 | 
					urls += [
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user