Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PEP-585 standard generic collections #184

Merged
merged 1 commit into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions django-stubs/apps/config.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Dict, Iterator, Optional, Type
from collections.abc import Iterator
from typing import Any, Optional

from django.apps.registry import Apps
from django.db.models.base import Model
Expand All @@ -13,13 +14,13 @@ class AppConfig:
verbose_name: str = ...
path: str = ...
models_module: Optional[str] = ...
models: Dict[str, Type[Model]] = ...
models: dict[str, type[Model]] = ...
def __init__(self, app_name: str, app_module: Optional[Any]) -> None: ...
@classmethod
def create(cls, entry: str) -> AppConfig: ...
def get_model(self, model_name: str, require_ready: bool = ...) -> Type[Model]: ...
def get_model(self, model_name: str, require_ready: bool = ...) -> type[Model]: ...
def get_models(
self, include_auto_created: bool = ..., include_swapped: bool = ...
) -> Iterator[Type[Model]]: ...
) -> Iterator[type[Model]]: ...
def import_models(self) -> None: ...
def ready(self) -> None: ...
21 changes: 11 additions & 10 deletions django-stubs/apps/registry.pyi
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import threading
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type, Union
from collections.abc import Callable, Iterable
from typing import Any, Optional, Union

from django.db.models.base import Model

from .config import AppConfig

class Apps:
all_models: Dict[str, Dict[str, Type[Model]]] = ...
app_configs: Dict[str, AppConfig] = ...
stored_app_configs: List[Any] = ...
all_models: dict[str, dict[str, type[Model]]] = ...
app_configs: dict[str, AppConfig] = ...
stored_app_configs: list[Any] = ...
apps_ready: bool = ...
ready_event: threading.Event = ...
loading: bool = ...
_pending_operations: Dict[Tuple[str, str], List[Any]]
_pending_operations: dict[tuple[str, str], list[Any]]
models_ready: bool = ...
ready: bool = ...
def __init__(
Expand All @@ -28,14 +29,14 @@ class Apps:
# it's not possible to support it in plugin properly now
def get_models(
self, include_auto_created: bool = ..., include_swapped: bool = ...
) -> List[Type[Model]]: ...
) -> list[type[Model]]: ...
def get_model(
self, app_label: str, model_name: Optional[str] = ..., require_ready: bool = ...
) -> Type[Model]: ...
def register_model(self, app_label: str, model: Type[Model]) -> None: ...
) -> type[Model]: ...
def register_model(self, app_label: str, model: type[Model]) -> None: ...
def is_installed(self, app_name: str) -> bool: ...
def get_containing_app_config(self, object_name: str) -> Optional[AppConfig]: ...
def get_registered_model(self, app_label: str, model_name: str) -> Type[Model]: ...
def get_registered_model(self, app_label: str, model_name: str) -> type[Model]: ...
def get_swappable_settings_name(self, to_string: str) -> Optional[str]: ...
def set_available_apps(self, available: Iterable[str]) -> None: ...
def unset_available_apps(self) -> None: ...
Expand All @@ -45,6 +46,6 @@ class Apps:
def lazy_model_operation(
self, function: Callable[..., Any], *model_keys: Any
) -> None: ...
def do_pending_operations(self, model: Type[Model]) -> None: ...
def do_pending_operations(self, model: type[Model]) -> None: ...

apps: Apps
67 changes: 35 additions & 32 deletions django-stubs/conf/global_settings.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ Default Django settings. Override these with settings in the module pointed to
by the DJANGO_SETTINGS_MODULE environment variable.
"""

from collections.abc import Sequence
from re import Pattern

# This is defined here as a do-nothing function because we can't import
# django.utils.translation -- that module depends on the settings.
from typing import Any, Dict, List, Optional, Pattern, Protocol, Sequence, Tuple, Union
from typing import Any, Optional, Protocol, Union

####################
# CORE #
Expand All @@ -19,16 +22,16 @@ DEBUG_PROPAGATE_EXCEPTIONS: bool = ...

# People who get code error notifications.
# In the format [('Full Name', '[email protected]'), ('Full Name', '[email protected]')]
ADMINS: List[Tuple[str, str]] = ...
ADMINS: list[tuple[str, str]] = ...

# List of IP addresses, as strings, that:
# * See debug comments, when DEBUG is true
# * Receive x-headers
INTERNAL_IPS: List[str] = ...
INTERNAL_IPS: list[str] = ...

# Hosts/domain names that are valid for this site.
# "*" matches anything, ".example.com" matches example.com and all subdomains
ALLOWED_HOSTS: List[str] = ...
ALLOWED_HOSTS: list[str] = ...

# Local time zone for this installation. All choices can be found here:
# https://en.wikipedia.org/wiki/List_of_tz_zones_by_name (although not all
Expand All @@ -44,15 +47,15 @@ USE_TZ: bool = ...
LANGUAGE_CODE: str = ...

# Languages we provide translations for, out of the box.
LANGUAGES: List[Tuple[str, str]] = ...
LANGUAGES: list[tuple[str, str]] = ...

# Languages using BiDi (right-to-left) layout
LANGUAGES_BIDI: List[str] = ...
LANGUAGES_BIDI: list[str] = ...

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N: bool = ...
LOCALE_PATHS: List[str] = ...
LOCALE_PATHS: list[str] = ...

# Settings for language cookie
LANGUAGE_COOKIE_NAME: str = ...
Expand Down Expand Up @@ -81,13 +84,13 @@ FILE_CHARSET: str = ...
SERVER_EMAIL: str = ...

# Database connection info. If left empty, will default to the dummy backend.
DATABASES: Dict[str, Dict[str, Any]] = ...
DATABASES: dict[str, dict[str, Any]] = ...

# Classes used to implement DB routing behavior.
class Router(Protocol):
def allow_migrate(self, db: Any, app_label: Any, **hints: Any) -> Any: ...

DATABASE_ROUTERS: List[Union[str, Router]] = ...
DATABASE_ROUTERS: list[Union[str, Router]] = ...

# The email backend to use. For possible shortcuts see django.core.mail.
# The default is to use the SMTP backend.
Expand All @@ -114,9 +117,9 @@ EMAIL_SSL_KEYFILE: Optional[str] = ...
EMAIL_TIMEOUT: Optional[int] = ...

# List of strings representing installed apps.
INSTALLED_APPS: List[str] = ...
INSTALLED_APPS: list[str] = ...

TEMPLATES: List[Dict[str, Any]] = ...
TEMPLATES: list[dict[str, Any]] = ...

# Default form rendering class.
FORM_RENDERER: str = ...
Expand Down Expand Up @@ -148,9 +151,9 @@ FORCE_SCRIPT_NAME = None
# re.compile(r'^SiteSucker.*'),
# re.compile(r'^sohu-search'),
# ]
DISALLOWED_USER_AGENTS: List[Pattern[str]] = ...
DISALLOWED_USER_AGENTS: list[Pattern[str]] = ...

ABSOLUTE_URL_OVERRIDES: Dict[str, Any] = ...
ABSOLUTE_URL_OVERRIDES: dict[str, Any] = ...

# List of compiled regular expression objects representing URLs that need not
# be reported by BrokenLinkEmailsMiddleware. Here are a few examples:
Expand All @@ -162,7 +165,7 @@ ABSOLUTE_URL_OVERRIDES: Dict[str, Any] = ...
# re.compile(r'^/phpmyadmin/'),
# re.compile(r'\.(cgi|php|pl)$'),
# ]
IGNORABLE_404_URLS: List[Pattern[str]] = ...
IGNORABLE_404_URLS: list[Pattern[str]] = ...

# A secret key for this particular Django installation. Used in secret-key
# hashing algorithms. Set this in your settings, or Django will complain
Expand All @@ -189,7 +192,7 @@ STATIC_ROOT: Optional[str] = ...
STATIC_URL: Optional[str] = ...
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

surprised it didn't update Optional[str] to str | None

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this will be updated in the next PR I prepared to use PEP-604 (A | B and A | None) syntax. The changes are huge I had to split them to multiple PRs.


# List of upload handler classes to be applied in order.
FILE_UPLOAD_HANDLERS: List[str] = ...
FILE_UPLOAD_HANDLERS: list[str] = ...

# Maximum size, in bytes, of a request before it will be streamed to the
# file system instead of into memory.
Expand Down Expand Up @@ -258,20 +261,20 @@ SHORT_DATETIME_FORMAT: str = ...
# See all available format string here:
# https://docs.python.org/library/datetime.html#strftime-behavior
# * Note that these format strings are different from the ones to display dates
DATE_INPUT_FORMATS: List[str] = ...
DATE_INPUT_FORMATS: list[str] = ...

# Default formats to be used when parsing times from input boxes, in order
# See all available format string here:
# https://docs.python.org/library/datetime.html#strftime-behavior
# * Note that these format strings are different from the ones to display dates
TIME_INPUT_FORMATS: List[str] = ... # '14:30:59' # '14:30:59.000200' # '14:30'
TIME_INPUT_FORMATS: list[str] = ... # '14:30:59' # '14:30:59.000200' # '14:30'

# Default formats to be used when parsing dates and times from input boxes,
# in order
# See all available format string here:
# https://docs.python.org/library/datetime.html#strftime-behavior
# * Note that these format strings are different from the ones to display dates
DATETIME_INPUT_FORMATS: List[str] = ...
DATETIME_INPUT_FORMATS: list[str] = ...

# First day of week, to be used on calendars
# 0 means Sunday, 1 means Monday...
Expand Down Expand Up @@ -314,7 +317,7 @@ WSGI_APPLICATION: Optional[str] = ...
# that header/value, request.is_secure() will return True.
# WARNING! Only set this if you fully understand what you're doing. Otherwise,
# you may be opening yourself up to a security risk.
SECURE_PROXY_SSL_HEADER: Optional[Tuple[str, str]] = ...
SECURE_PROXY_SSL_HEADER: Optional[tuple[str, str]] = ...

##############
# MIDDLEWARE #
Expand All @@ -323,7 +326,7 @@ SECURE_PROXY_SSL_HEADER: Optional[Tuple[str, str]] = ...
# List of middleware to use. Order is important; in the request phase, these
# middleware will be applied in the order given, and in the response
# phase the middleware will be applied in reverse order.
MIDDLEWARE: List[str] = ...
MIDDLEWARE: list[str] = ...

############
# SESSIONS #
Expand Down Expand Up @@ -363,7 +366,7 @@ SESSION_SERIALIZER = "django.contrib.sessions.serializers.JSONSerializer"
#########

# The cache backends to use.
CACHES: Dict[str, Dict[str, Any]] = ...
CACHES: dict[str, dict[str, Any]] = ...
CACHE_MIDDLEWARE_KEY_PREFIX = ""
CACHE_MIDDLEWARE_SECONDS = 600
CACHE_MIDDLEWARE_ALIAS = "default"
Expand All @@ -388,9 +391,9 @@ PASSWORD_RESET_TIMEOUT_DAYS = 3
# the first hasher in this list is the preferred algorithm. any
# password using different algorithms will be converted automatically
# upon login
PASSWORD_HASHERS: List[str] = ...
PASSWORD_HASHERS: list[str] = ...

AUTH_PASSWORD_VALIDATORS: List[Dict[str, str]] = ...
AUTH_PASSWORD_VALIDATORS: list[dict[str, str]] = ...

###########
# SIGNING #
Expand All @@ -415,7 +418,7 @@ CSRF_COOKIE_SECURE = False
CSRF_COOKIE_HTTPONLY = False
CSRF_COOKIE_SAMESITE: Optional[str] = ...
CSRF_HEADER_NAME = "HTTP_X_CSRFTOKEN"
CSRF_TRUSTED_ORIGINS: List[str] = ...
CSRF_TRUSTED_ORIGINS: list[str] = ...
CSRF_USE_SESSIONS = False

############
Expand All @@ -436,7 +439,7 @@ MESSAGE_STORAGE = "django.contrib.messages.storage.fallback.FallbackStorage"
LOGGING_CONFIG = "logging.config.dictConfig"

# Custom logging configuration.
LOGGING: Dict[str, Any] = ...
LOGGING: dict[str, Any] = ...

# Default exception reporter filter class used in case none has been
# specifically assigned to the HttpRequest instance.
Expand All @@ -451,35 +454,35 @@ TEST_RUNNER = "django.test.runner.DiscoverRunner"

# Apps that don't need to be serialized at test database creation time
# (only apps with migrations are to start with)
TEST_NON_SERIALIZED_APPS: List[str] = ...
TEST_NON_SERIALIZED_APPS: list[str] = ...

############
# FIXTURES #
############

# The list of directories to search for fixtures
FIXTURE_DIRS: List[str] = ...
FIXTURE_DIRS: list[str] = ...

###############
# STATICFILES #
###############

# A list of locations of additional static files
STATICFILES_DIRS: List[str] = ...
STATICFILES_DIRS: list[str] = ...

# The default file storage backend used during the build process
STATICFILES_STORAGE: str = ...

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS: List[str] = ...
STATICFILES_FINDERS: list[str] = ...

##############
# MIGRATIONS #
##############

# Migration module overrides for apps, by app label.
MIGRATION_MODULES: Dict[str, str] = ...
MIGRATION_MODULES: dict[str, str] = ...

#################
# SYSTEM CHECKS #
Expand All @@ -489,7 +492,7 @@ MIGRATION_MODULES: Dict[str, str] = ...
# issues like warnings, infos or debugs will not generate a message. Silencing
# serious issues like errors and criticals does not result in hiding the
# message, but Django will not stop you from e.g. running server.
SILENCED_SYSTEM_CHECKS: List[str] = ...
SILENCED_SYSTEM_CHECKS: list[str] = ...

#######################
# SECURITY MIDDLEWARE #
Expand All @@ -499,6 +502,6 @@ SECURE_CONTENT_TYPE_NOSNIFF = False
SECURE_HSTS_INCLUDE_SUBDOMAINS = False
SECURE_HSTS_PRELOAD = False
SECURE_HSTS_SECONDS = 0
SECURE_REDIRECT_EXEMPT: List[str] = ...
SECURE_REDIRECT_EXEMPT: list[str] = ...
SECURE_SSL_HOST = None
SECURE_SSL_REDIRECT = False
4 changes: 2 additions & 2 deletions django-stubs/conf/locale/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from typing import Any, Dict
from typing import Any

LANG_INFO: Dict[str, Any] = ...
LANG_INFO: dict[str, Any] = ...
13 changes: 7 additions & 6 deletions django-stubs/conf/urls/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Stubs for django.conf.urls (Python 3.5)
from typing import Any, Callable, Dict, List, Optional, Tuple, Union, overload
from collections.abc import Callable
from typing import Any, Optional, Union, overload

from django.http.response import HttpResponse, HttpResponseBase
from django.urls import URLPattern, URLResolver
Expand All @@ -9,24 +10,24 @@ handler403: Union[str, Callable[..., HttpResponse]] = ...
handler404: Union[str, Callable[..., HttpResponse]] = ...
handler500: Union[str, Callable[..., HttpResponse]] = ...

IncludedURLConf = Tuple[List[URLResolver], Optional[str], Optional[str]]
IncludedURLConf = tuple[list[URLResolver], Optional[str], Optional[str]]

def include(arg: Any, namespace: str = ..., app_name: str = ...) -> IncludedURLConf: ...
@overload
def url(
regex: str,
view: Callable[..., HttpResponseBase],
kwargs: Dict[str, Any] = ...,
kwargs: dict[str, Any] = ...,
name: str = ...,
) -> URLPattern: ...
@overload
def url(
regex: str, view: IncludedURLConf, kwargs: Dict[str, Any] = ..., name: str = ...
regex: str, view: IncludedURLConf, kwargs: dict[str, Any] = ..., name: str = ...
) -> URLResolver: ...
@overload
def url(
regex: str,
view: List[Union[URLResolver, str]],
kwargs: Dict[str, Any] = ...,
view: list[Union[URLResolver, str]],
kwargs: dict[str, Any] = ...,
name: str = ...,
) -> URLResolver: ...
9 changes: 5 additions & 4 deletions django-stubs/conf/urls/i18n.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import Any, Callable, List, Tuple
from collections.abc import Callable
from typing import Any

from django.urls.resolvers import URLPattern

def i18n_patterns(
*urls: Any, prefix_default_language: bool = ...
) -> List[List[URLPattern]]: ...
def is_language_prefix_patterns_used(urlconf: str) -> Tuple[bool, bool]: ...
) -> list[list[URLPattern]]: ...
def is_language_prefix_patterns_used(urlconf: str) -> tuple[bool, bool]: ...

urlpatterns: List[Callable[..., Any]]
urlpatterns: list[Callable[..., Any]]
5 changes: 3 additions & 2 deletions django-stubs/conf/urls/static.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Any, Callable, List
from collections.abc import Callable
from typing import Any

from django.urls.resolvers import URLPattern

def static(
prefix: str, view: Callable[..., Any] = ..., **kwargs: Any
) -> List[URLPattern]: ...
) -> list[URLPattern]: ...
Loading