From 2684f6874c3bbf4c14f61475c15a2f7a0953d865 Mon Sep 17 00:00:00 2001 From: Konstantin Alekseev Date: Fri, 25 Sep 2026 09:47:51 +0300 Subject: [PATCH] sync django.conf and django.urls with django-stubs --- django-stubs/conf/__init__.pyi | 31 ++- django-stubs/conf/global_settings.pyi | 377 +++++++++++++++----------- django-stubs/conf/locale/__init__.pyi | 2 +- django-stubs/conf/urls/__init__.pyi | 36 +-- django-stubs/conf/urls/i18n.pyi | 9 +- django-stubs/conf/urls/static.pyi | 3 +- django-stubs/urls/__init__.pyi | 32 +++ django-stubs/urls/base.pyi | 52 ++-- django-stubs/urls/conf.pyi | 56 ++-- django-stubs/urls/converters.pyi | 24 +- django-stubs/urls/resolvers.pyi | 152 ++++++----- s/sync | 134 ++++++--- s/sync-files.txt | 81 ------ 13 files changed, 538 insertions(+), 451 deletions(-) delete mode 100644 s/sync-files.txt diff --git a/django-stubs/conf/__init__.pyi b/django-stubs/conf/__init__.pyi index 0e146029f..b0fbe5318 100644 --- a/django-stubs/conf/__init__.pyi +++ b/django-stubs/conf/__init__.pyi @@ -1,27 +1,44 @@ -from typing import Any, Literal +from typing import Any, Literal, type_check_only from django.utils.functional import LazyObject +from typing_extensions import Self, override + +# explicit dependency on standard settings to make it loaded +from . import global_settings as global_settings ENVIRONMENT_VARIABLE: Literal["DJANGO_SETTINGS_MODULE"] DEFAULT_STORAGE_ALIAS: Literal["default"] STATICFILES_STORAGE_ALIAS: Literal["staticfiles"] -DEFAULT_CONTENT_TYPE_DEPRECATED_MSG: str = ... -FILE_CHARSET_DEPRECATED_MSG: str = ... +# required for plugin to be able to distinguish this specific instance of LazySettings from others +@type_check_only class _DjangoConfLazyObject(LazyObject): + @override def __getattr__(self, item: Any) -> Any: ... class LazySettings(_DjangoConfLazyObject): - configured: bool - def configure(self, default_settings: Any = ..., **options: Any) -> Any: ... + SETTINGS_MODULE: str + @property + def configured(self) -> bool: ... + def configure(self, default_settings: Any = ..., **options: Any) -> None: ... -settings: LazySettings = ... +settings: LazySettings class Settings: + SETTINGS_MODULE: str def __init__(self, settings_module: str) -> None: ... def is_overridden(self, setting: str) -> bool: ... -class UserSettingsHolder: ... +class UserSettingsHolder: + SETTINGS_MODULE: None + def __init__(self, default_settings: Any) -> None: ... + def __getattr__(self, name: str) -> Any: ... + @override + def __setattr__(self, name: str, value: Any) -> None: ... + @override + def __delattr__(self, name: str) -> None: ... + def is_overridden(self, setting: str) -> bool: ... class SettingsReference(str): + def __new__(self, value: Any, setting_name: str) -> Self: ... # pyright: ignore[reportSelfClsParameterName] def __init__(self, value: str, setting_name: str) -> None: ... diff --git a/django-stubs/conf/global_settings.pyi b/django-stubs/conf/global_settings.pyi index f7c913024..38b5f8277 100644 --- a/django-stubs/conf/global_settings.pyi +++ b/django-stubs/conf/global_settings.pyi @@ -1,147 +1,152 @@ -""" -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 collections.abc import Collection, Mapping, Sequence from re import Pattern +from typing import Any, Literal, Protocol, TypeAlias, TypedDict, type_check_only + +from django.utils.functional import _StrOrPromise +from typing_extensions import NotRequired # 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, Protocol, TypeAlias +def gettext_noop(s: str) -> str: ... -from django.utils.functional import _StrOrPromise +# Note: the tuple element format for ADMINS or MANAGERS is deprecated. Use a +# list of strings instead. +_Admins: TypeAlias = list[str] | list[tuple[str, str]] #################### # CORE # #################### -DEBUG: bool = ... +DEBUG: bool # Whether the framework should propagate raw exceptions rather than catching # them. This is useful under some testing situations and should never be used # on a live site. -DEBUG_PROPAGATE_EXCEPTIONS: bool = ... +DEBUG_PROPAGATE_EXCEPTIONS: bool # People who get code error notifications. # In the format [('Full Name', 'email@example.com'), ('Full Name', 'anotheremail@example.com')] -ADMINS: list[tuple[str, str]] = ... +ADMINS: _Admins # 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 # systems may support all possibilities). When USE_TZ is True, this is # interpreted as the default user time zone. -TIME_ZONE: str = ... +TIME_ZONE: str # If you set this to True, Django will use timezone-aware datetimes. -USE_TZ: bool = ... +USE_TZ: bool # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html -LANGUAGE_CODE: str = ... +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] = ... +USE_I18N: bool +LOCALE_PATHS: list[str] # Settings for language cookie -LANGUAGE_COOKIE_NAME: str = ... -LANGUAGE_COOKIE_AGE: int | None = ... -LANGUAGE_COOKIE_DOMAIN: str | None = ... -LANGUAGE_COOKIE_PATH: str = ... - -# If you set this to True, Django will format dates, numbers and calendars -# according to user current locale. -USE_L10N: bool = ... +LANGUAGE_COOKIE_NAME: str +LANGUAGE_COOKIE_AGE: int | None +LANGUAGE_COOKIE_DOMAIN: str | None +LANGUAGE_COOKIE_PATH: str +LANGUAGE_COOKIE_HTTPONLY: bool +LANGUAGE_COOKIE_SAMESITE: Literal["Lax", "Strict", "None", False] | None +LANGUAGE_COOKIE_SECURE: bool # Not-necessarily-technical managers of the site. They get broken link # notifications and other various emails. -MANAGERS = ADMINS +MANAGERS: _Admins -# Default content type and charset to use for all HttpResponse objects, if a +# Default charset to use for all HttpResponse objects, if a # MIME type isn't manually specified. These are used to construct the # Content-Type header. -DEFAULT_CONTENT_TYPE: str = ... -DEFAULT_CHARSET: str = ... +DEFAULT_CHARSET: str -# Encoding of files read from disk (template and initial SQL files). -FILE_CHARSET: str = ... +# `SERIALIZATION_MODULES` is a dictionary (`dict[str, str]`) of modules containing serializer definitions. +# Because Django doesn't define it, we can't provide its type here. Use `getattr` for type-safe access +# e.g. `getattr(settings, "SERIALIZATION_MODULES")` # Email address that error messages come from. -SERVER_EMAIL: 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. +@type_check_only class Router(Protocol): - def allow_migrate(self, db: Any, app_label: Any, **hints: Any) -> Any: ... + def allow_migrate(self, db: str, app_label: str, **hints: Any) -> bool | None: ... -DATABASE_ROUTERS: list[str | Router] = ... +DATABASE_ROUTERS: list[str | Router] # The email backend to use. For possible shortcuts see django.core.mail. # The default is to use the SMTP backend. # Third-party backends can be specified by providing a Python path # to a module that defines an EmailBackend class. -EMAIL_BACKEND: str = ... +EMAIL_BACKEND: str + +# `EMAIL_FILE_PATH` is a `str` indicating the directory used by the file email backend to store output files. +# Because Django doesn't define it, we can't provide its type here. Use `getattr` for type-safe access +# e.g. `getattr(settings, "EMAIL_FILE_PATH")` # Host for sending email. -EMAIL_HOST: str = ... +EMAIL_HOST: str # Port for sending email. -EMAIL_PORT: int = ... +EMAIL_PORT: int # Whether to send SMTP 'Date' header in the local time zone or in UTC. -EMAIL_USE_LOCALTIME: bool = ... +EMAIL_USE_LOCALTIME: bool # Optional SMTP authentication information for EMAIL_HOST. -EMAIL_HOST_USER: str = ... -EMAIL_HOST_PASSWORD: str = ... -EMAIL_USE_TLS: bool = ... -EMAIL_USE_SSL: bool = ... -EMAIL_SSL_CERTFILE: str | None = ... -EMAIL_SSL_KEYFILE: str | None = ... -EMAIL_TIMEOUT: int | None = ... +EMAIL_HOST_USER: str +EMAIL_HOST_PASSWORD: str +EMAIL_USE_TLS: bool +EMAIL_USE_SSL: bool +EMAIL_SSL_CERTFILE: str | None +EMAIL_SSL_KEYFILE: str | None +EMAIL_TIMEOUT: int | None # List of strings representing installed apps. -INSTALLED_APPS: list[str] = ... +INSTALLED_APPS: list[str] TEMPLATES: list[dict[str, Any]] = ... # Default form rendering class. -FORM_RENDERER: str = ... +FORM_RENDERER: str # Default email address to use for various automated correspondence from # the site managers. -DEFAULT_FROM_EMAIL: str = ... +DEFAULT_FROM_EMAIL: str # Subject-line prefix for email messages send with django.core.mail.mail_admins # or ...mail_managers. Make sure to include the trailing space. -EMAIL_SUBJECT_PREFIX: str = ... +EMAIL_SUBJECT_PREFIX: str # Whether to append trailing slashes to URLs. -APPEND_SLASH: bool = ... +APPEND_SLASH: bool # Whether to prepend the "www." subdomain to URLs that don't have it. -PREPEND_WWW: bool = ... +PREPEND_WWW: bool # Override the server-derived value of SCRIPT_NAME -FORCE_SCRIPT_NAME: TypeAlias = None +FORCE_SCRIPT_NAME: str | None # List of compiled regular expression objects representing User-Agent strings # that are not allowed to visit any page, systemwide. Use this for bad @@ -153,9 +158,9 @@ FORCE_SCRIPT_NAME: TypeAlias = 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: @@ -167,150 +172,168 @@ 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]] + +# `ROOT_URLCONF` is a string representing the full Python import path to the root `URLconf`. +# Because Django doesn't define it, we can't provide its type here. Use `getattr` for type-safe access +# e.g. `getattr(settings, "ROOT_URLCONF")` # A secret key for this particular Django installation. Used in secret-key # hashing algorithms. Set this in your settings, or Django will complain # loudly. -SECRET_KEY: str = ... +SECRET_KEY: str | bytes + +# A list of fallback secret keys for a particular Django installation. These +# are used to allow rotation of the SECRET_KEY. +SECRET_KEY_FALLBACKS: list[str | bytes] -# Default file storage mechanism that holds media. -DEFAULT_FILE_STORAGE: str = ... +STORAGES: dict[str, dict[str, Any]] # Absolute filesystem path to the directory that will hold user-uploaded files. # Example: "/var/www/example.com/media/" -MEDIA_ROOT: str = ... +MEDIA_ROOT: str # URL that handles the media served from MEDIA_ROOT. # Examples: "http://example.com/media/", "http://media.example.com/" -MEDIA_URL: str = ... +MEDIA_URL: str + +# `SITE_ID` is the ID, as an integer, of the current site in the `django_site` database table. +# Because Django doesn't define it, we can't provide its type here. Use `getattr` for type-safe access +# e.g. `getattr(settings, "SITE_ID")` # Absolute path to the directory static files should be collected to. # Example: "/var/www/example.com/static/" -STATIC_ROOT: str | None = ... +STATIC_ROOT: str | None # URL that handles the static files served from STATIC_ROOT. # Example: "http://example.com/static/", "http://static.example.com/" -STATIC_URL: str | None = ... +STATIC_URL: str | None # 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. -FILE_UPLOAD_MAX_MEMORY_SIZE: int = ... # i.e. 2.5 MB +FILE_UPLOAD_MAX_MEMORY_SIZE: int # i.e. 2.5 MB # Maximum size in bytes of request data (excluding file uploads) that will be # read before a SuspiciousOperation (RequestDataTooBig) is raised. -DATA_UPLOAD_MAX_MEMORY_SIZE: int = ... # i.e. 2.5 MB +DATA_UPLOAD_MAX_MEMORY_SIZE: int # i.e. 2.5 MB # Maximum number of GET/POST parameters that will be read before a # SuspiciousOperation (TooManyFieldsSent) is raised. -DATA_UPLOAD_MAX_NUMBER_FIELDS: int = ... +DATA_UPLOAD_MAX_NUMBER_FIELDS: int + +# Maximum number of files encoded in a multipart upload that will be read +# before a SuspiciousOperation (TooManyFilesSent) is raised. +DATA_UPLOAD_MAX_NUMBER_FILES: int # Directory in which upload streamed files will be temporarily saved. A value of # `None` will make Django use the operating system's default temporary directory # (i.e. "/tmp" on *nix systems). -FILE_UPLOAD_TEMP_DIR: str | None = ... +FILE_UPLOAD_TEMP_DIR: str | None # The numeric mode to set newly-uploaded files to. The value should be a mode # you'd pass directly to os.chmod; see https://docs.python.org/library/os.html#files-and-directories. -FILE_UPLOAD_PERMISSIONS: TypeAlias = None +FILE_UPLOAD_PERMISSIONS: int # The numeric mode to assign to newly-created directories, when uploading files. # The value should be a mode as you'd pass to os.chmod; # see https://docs.python.org/library/os.html#files-and-directories. -FILE_UPLOAD_DIRECTORY_PERMISSIONS: TypeAlias = None +FILE_UPLOAD_DIRECTORY_PERMISSIONS: int | None # Python module path where user will place custom format definition. # The directory where this setting is pointing should contain subdirectories # named as the locales, containing a formats.py file # (i.e. "myproject.locale" for myproject/locale/en/formats.py etc. use) -FORMAT_MODULE_PATH: str | None = ... +FORMAT_MODULE_PATH: str | None # Default formatting for date objects. See all available format strings here: -# https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date -DATE_FORMAT: str = ... +# https://docs.djangoproject.com/en/stable/ref/templates/builtins/#date +DATE_FORMAT: str # Default formatting for datetime objects. See all available format strings here: -# https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date -DATETIME_FORMAT: str = ... +# https://docs.djangoproject.com/en/stable/ref/templates/builtins/#date +DATETIME_FORMAT: str # Default formatting for time objects. See all available format strings here: -# https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date -TIME_FORMAT: str = ... +# https://docs.djangoproject.com/en/stable/ref/templates/builtins/#date +TIME_FORMAT: str # Default formatting for date objects when only the year and month are relevant. # See all available format strings here: -# https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date -YEAR_MONTH_FORMAT: str = ... +# https://docs.djangoproject.com/en/stable/ref/templates/builtins/#date +YEAR_MONTH_FORMAT: str # Default formatting for date objects when only the month and day are relevant. # See all available format strings here: -# https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date -MONTH_DAY_FORMAT: str = ... +# https://docs.djangoproject.com/en/stable/ref/templates/builtins/#date +MONTH_DAY_FORMAT: str # Default short formatting for date objects. See all available format strings here: -# https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date -SHORT_DATE_FORMAT: str = ... +# https://docs.djangoproject.com/en/stable/ref/templates/builtins/#date +SHORT_DATE_FORMAT: str # Default short formatting for datetime objects. # See all available format strings here: -# https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date -SHORT_DATETIME_FORMAT: str = ... +# https://docs.djangoproject.com/en/stable/ref/templates/builtins/#date +SHORT_DATETIME_FORMAT: str # Default formats to be used when parsing dates 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 -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... -FIRST_DAY_OF_WEEK: int = ... +FIRST_DAY_OF_WEEK: int # Decimal separator symbol -DECIMAL_SEPARATOR: str = ... +DECIMAL_SEPARATOR: str # Boolean that sets whether to add thousand separator when formatting numbers -USE_THOUSAND_SEPARATOR: bool = ... +USE_THOUSAND_SEPARATOR: bool # Number of digits that will be together, when splitting them by # THOUSAND_SEPARATOR. 0 means no grouping, 3 means splitting by thousands... -NUMBER_GROUPING: int = ... +NUMBER_GROUPING: int # Thousand separator symbol -THOUSAND_SEPARATOR: str = ... +THOUSAND_SEPARATOR: str # The tablespaces to use for each model when not specified otherwise. -DEFAULT_TABLESPACE: str = ... -DEFAULT_INDEX_TABLESPACE: str = ... +DEFAULT_TABLESPACE: str +DEFAULT_INDEX_TABLESPACE: str + +# Default primary key field type. +DEFAULT_AUTO_FIELD: str # Default X-Frame-Options header value -X_FRAME_OPTIONS: str = ... +X_FRAME_OPTIONS: str -USE_X_FORWARDED_HOST: bool = ... -USE_X_FORWARDED_PORT: bool = ... +USE_X_FORWARDED_HOST: bool +USE_X_FORWARDED_PORT: bool # The Python dotted path to the WSGI application that Django's internal server # (runserver) will use. If `None`, the return value of # 'django.core.wsgi.get_wsgi_application' is used, thus preserving the same # behavior as previous versions of Django. Otherwise this should point to an # actual WSGI application object. -WSGI_APPLICATION: str | None = ... +WSGI_APPLICATION: str | None # If your Django app is behind a proxy that sets a header to specify secure # connections, AND that proxy ensures that user-submitted headers with the @@ -319,7 +342,7 @@ WSGI_APPLICATION: str | None = ... # 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: tuple[str, str] | None = ... +SECURE_PROXY_SSL_HEADER: tuple[str, str] | None ############## # MIDDLEWARE # @@ -328,80 +351,86 @@ SECURE_PROXY_SSL_HEADER: tuple[str, str] | None = ... # 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 # ############ # Cache to store session data if using the cache session backend. -SESSION_CACHE_ALIAS: str = "default" +SESSION_CACHE_ALIAS: str # Cookie name. This can be whatever you want. -SESSION_COOKIE_NAME: str = "sessionid" +SESSION_COOKIE_NAME: str # Age of cookie, in seconds (default: 2 weeks). -SESSION_COOKIE_AGE: int = ... +SESSION_COOKIE_AGE: int # A string like "example.com", or None for standard domain cookie. -SESSION_COOKIE_DOMAIN: str | None = ... +SESSION_COOKIE_DOMAIN: str | None # Whether the session cookie should be secure (https:// only). -SESSION_COOKIE_SECURE: bool = False +SESSION_COOKIE_SECURE: bool # The path of the session cookie. -SESSION_COOKIE_PATH: str = "/" +SESSION_COOKIE_PATH: str # Whether to use the non-RFC standard httpOnly flag (IE, FF3+, others) -SESSION_COOKIE_HTTPONLY: bool = True +SESSION_COOKIE_HTTPONLY: bool # Whether to set the flag restricting cookie leaks on cross-site requests. -# This can be 'Lax', 'Strict', or None to disable the flag. -SESSION_COOKIE_SAMESITE: str | None = ... +# This can be 'Lax', 'Strict', 'None', or False to disable the flag. +SESSION_COOKIE_SAMESITE: Literal["Lax", "Strict", "None", False] # Whether to save the session data on every request. -SESSION_SAVE_EVERY_REQUEST: bool = False +SESSION_SAVE_EVERY_REQUEST: bool # Whether a user's session cookie expires when the Web browser is closed. -SESSION_EXPIRE_AT_BROWSER_CLOSE: bool = False +SESSION_EXPIRE_AT_BROWSER_CLOSE: bool # The module to store session data -SESSION_ENGINE: str = "django.contrib.sessions.backends.db" +SESSION_ENGINE: str # Directory to store session files if using the file session module. If None, # the backend will use a sensible default. -SESSION_FILE_PATH: str | None = ... +SESSION_FILE_PATH: str | None # class to serialize session data -SESSION_SERIALIZER: str = "django.contrib.sessions.serializers.JSONSerializer" +SESSION_SERIALIZER: str ######### # CACHE # ######### # The cache backends to use. -CACHES: dict[str, dict[str, Any]] = ... -CACHE_MIDDLEWARE_KEY_PREFIX: str = "" -CACHE_MIDDLEWARE_SECONDS: int = 600 -CACHE_MIDDLEWARE_ALIAS: str = "default" +CACHES: dict[str, dict[str, Any]] +CACHE_MIDDLEWARE_KEY_PREFIX: str +CACHE_MIDDLEWARE_SECONDS: int +CACHE_MIDDLEWARE_ALIAS: str ################## # AUTHENTICATION # ################## -AUTH_USER_MODEL: str = ... +AUTH_USER_MODEL: str -AUTHENTICATION_BACKENDS: Sequence[str] = ... +AUTHENTICATION_BACKENDS: Sequence[str] -LOGIN_URL: _StrOrPromise = ... +LOGIN_URL: _StrOrPromise -LOGIN_REDIRECT_URL: _StrOrPromise = ... +LOGIN_REDIRECT_URL: _StrOrPromise -LOGOUT_REDIRECT_URL: _StrOrPromise | None = ... +LOGOUT_REDIRECT_URL: _StrOrPromise | None -# The number of days a password reset link is valid for -PASSWORD_RESET_TIMEOUT_DAYS: int = 3 +# The number of seconds a password reset link is valid for +PASSWORD_RESET_TIMEOUT: int # 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]] = ... +@type_check_only +class _AuthPasswordValidatorsDict(TypedDict): + NAME: str + OPTIONS: NotRequired[dict[str, Any]] + +AUTH_PASSWORD_VALIDATORS: list[_AuthPasswordValidatorsDict] ########### # SIGNING # ########### -SIGNING_BACKEND: str = "django.core.signing.TimestampSigner" +SIGNED_COOKIE_LEGACY_SALT_FALLBACK: bool +SIGNING_BACKEND: str ######## # CSRF # @@ -409,26 +438,26 @@ SIGNING_BACKEND: str = "django.core.signing.TimestampSigner" # Dotted path to callable to be used as view when a request is # rejected by the CSRF middleware. -CSRF_FAILURE_VIEW: str = "django.views.csrf.csrf_failure" +CSRF_FAILURE_VIEW: str # Settings for CSRF cookie. -CSRF_COOKIE_NAME: str = "csrftoken" -CSRF_COOKIE_AGE: int = ... -CSRF_COOKIE_DOMAIN: TypeAlias = None -CSRF_COOKIE_PATH: str = "/" -CSRF_COOKIE_SECURE: bool = False -CSRF_COOKIE_HTTPONLY: bool = False -CSRF_COOKIE_SAMESITE: str | None = ... -CSRF_HEADER_NAME: str = "HTTP_X_CSRFTOKEN" -CSRF_TRUSTED_ORIGINS: list[str] = ... -CSRF_USE_SESSIONS: bool = False +CSRF_COOKIE_NAME: str +CSRF_COOKIE_AGE: int +CSRF_COOKIE_DOMAIN: str | None +CSRF_COOKIE_PATH: str +CSRF_COOKIE_SECURE: bool +CSRF_COOKIE_HTTPONLY: bool +CSRF_COOKIE_SAMESITE: Literal["Lax", "Strict", "None", False] +CSRF_HEADER_NAME: str +CSRF_TRUSTED_ORIGINS: list[str] +CSRF_USE_SESSIONS: bool ############ # MESSAGES # ############ # Class to use as messages backend -MESSAGE_STORAGE = ... +MESSAGE_STORAGE: str # Default values of MESSAGE_LEVEL and MESSAGE_TAGS are defined within # django.contrib.messages to avoid imports in this settings file. @@ -438,53 +467,54 @@ MESSAGE_STORAGE = ... ########### # The callable to use to configure logging -LOGGING_CONFIG: str = "logging.config.dictConfig" +LOGGING_CONFIG: str # Custom logging configuration. -LOGGING: dict[str, Any] = ... +LOGGING: dict[str, Any] + +# Default exception reporter class used in case none has been +# specifically assigned to the HttpRequest instance. +DEFAULT_EXCEPTION_REPORTER: str # Default exception reporter filter class used in case none has been # specifically assigned to the HttpRequest instance. -DEFAULT_EXCEPTION_REPORTER_FILTER: str = "django.views.debug.SafeExceptionReporterFilter" +DEFAULT_EXCEPTION_REPORTER_FILTER: str ########### # TESTING # ########### # The name of the class to use to run the test suite -TEST_RUNNER: str = "django.test.runner.DiscoverRunner" +TEST_RUNNER: str # 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] = ... - -# The default file storage backend used during the build process -STATICFILES_STORAGE: str = ... +STATICFILES_DIRS: list[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 | None] ################# # SYSTEM CHECKS # @@ -494,16 +524,33 @@ 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 # ####################### -SECURE_BROWSER_XSS_FILTER: bool = False -SECURE_CONTENT_TYPE_NOSNIFF: bool = False -SECURE_HSTS_INCLUDE_SUBDOMAINS: bool = False -SECURE_HSTS_PRELOAD: bool = False -SECURE_HSTS_SECONDS: int = 0 -SECURE_REDIRECT_EXEMPT: list[str] = ... -SECURE_SSL_HOST: TypeAlias = None -SECURE_SSL_REDIRECT: bool = False +SECURE_CONTENT_TYPE_NOSNIFF: bool +SECURE_CROSS_ORIGIN_OPENER_POLICY: str +SECURE_HSTS_INCLUDE_SUBDOMAINS: bool +SECURE_HSTS_PRELOAD: bool +SECURE_HSTS_SECONDS: int +SECURE_REDIRECT_EXEMPT: list[str] +SECURE_REFERRER_POLICY: str +SECURE_SSL_HOST: str | None +SECURE_SSL_REDIRECT: bool + +################## +# CSP MIDDLEWARE # +################## +SECURE_CSP: Mapping[str, Collection[str] | str] +SECURE_CSP_REPORT_ONLY: Mapping[str, Collection[str] | str] + +# RemovedInDjango70Warning: A transitional setting helpful in early adoption of +# HTTPS as the default protocol in urlize and urlizetrunc when no protocol is +# provided. Set to True to assume HTTPS during the Django 6.x release cycle. +URLIZE_ASSUME_HTTPS: bool + +######### +# TASKS # +######### +TASKS: dict[str, dict[str, Any]] diff --git a/django-stubs/conf/locale/__init__.pyi b/django-stubs/conf/locale/__init__.pyi index afbb3d2af..285cc8198 100644 --- a/django-stubs/conf/locale/__init__.pyi +++ b/django-stubs/conf/locale/__init__.pyi @@ -1,3 +1,3 @@ from typing import Any -LANG_INFO: dict[str, Any] = ... +LANG_INFO: dict[str, Any] diff --git a/django-stubs/conf/urls/__init__.pyi b/django-stubs/conf/urls/__init__.pyi index edbc86416..ae6405a3a 100644 --- a/django-stubs/conf/urls/__init__.pyi +++ b/django-stubs/conf/urls/__init__.pyi @@ -1,31 +1,9 @@ -# Stubs for django.conf.urls (Python 3.5) -from collections.abc import Callable -from typing import Any, TypeAlias, overload +from django.urls import include as include +from django.views import defaults -from django.http.response import HttpResponse, HttpResponseBase -from django.urls import URLPattern, URLResolver +__all__ = ["handler400", "handler403", "handler404", "handler500", "include"] -handler400: str | Callable[..., HttpResponse] = ... -handler403: str | Callable[..., HttpResponse] = ... -handler404: str | Callable[..., HttpResponse] = ... -handler500: str | Callable[..., HttpResponse] = ... - -IncludedURLConf: TypeAlias = tuple[list[URLResolver], str | None, str | None] - -def include(arg: Any, namespace: str = ..., app_name: str = ...) -> IncludedURLConf: ... -@overload -def url( - regex: str, - view: Callable[..., HttpResponseBase], - kwargs: dict[str, Any] = ..., - name: str = ..., -) -> URLPattern: ... -@overload -def url(regex: str, view: IncludedURLConf, kwargs: dict[str, Any] = ..., name: str = ...) -> URLResolver: ... -@overload -def url( - regex: str, - view: list[URLResolver | str], - kwargs: dict[str, Any] = ..., - name: str = ..., -) -> URLResolver: ... +handler400 = defaults.bad_request +handler403 = defaults.permission_denied +handler404 = defaults.page_not_found +handler500 = defaults.server_error diff --git a/django-stubs/conf/urls/i18n.pyi b/django-stubs/conf/urls/i18n.pyi index 6942d7500..5e7b3b619 100644 --- a/django-stubs/conf/urls/i18n.pyi +++ b/django-stubs/conf/urls/i18n.pyi @@ -1,9 +1,6 @@ -from collections.abc import Callable -from typing import Any +from django.urls import _AnyURL -from django.urls.resolvers import URLPattern - -def i18n_patterns(*urls: Any, prefix_default_language: bool = ...) -> list[list[URLPattern]]: ... +def i18n_patterns(*urls: _AnyURL, prefix_default_language: bool = ...) -> list[_AnyURL]: ... def is_language_prefix_patterns_used(urlconf: str) -> tuple[bool, bool]: ... -urlpatterns: list[Callable[..., Any]] +urlpatterns: list[_AnyURL] diff --git a/django-stubs/conf/urls/static.pyi b/django-stubs/conf/urls/static.pyi index 78510c79e..7ad81c959 100644 --- a/django-stubs/conf/urls/static.pyi +++ b/django-stubs/conf/urls/static.pyi @@ -1,6 +1,7 @@ from collections.abc import Callable from typing import Any +from django.http.response import HttpResponseBase from django.urls.resolvers import URLPattern -def static(prefix: str, view: Callable[..., Any] = ..., **kwargs: Any) -> list[URLPattern]: ... +def static(prefix: str, view: Callable[..., HttpResponseBase] = ..., **kwargs: Any) -> list[URLPattern]: ... diff --git a/django-stubs/urls/__init__.pyi b/django-stubs/urls/__init__.pyi index 0144ac266..0bb0faa3a 100644 --- a/django-stubs/urls/__init__.pyi +++ b/django-stubs/urls/__init__.pyi @@ -1,3 +1,5 @@ +from typing import TypeAlias + # noinspection PyUnresolvedReferences from .base import clear_script_prefix as clear_script_prefix from .base import clear_url_caches as clear_url_caches @@ -34,3 +36,33 @@ from .resolvers import get_resolver as get_resolver # noinspection PyUnresolvedReferences from .utils import get_callable as get_callable from .utils import get_mod_func as get_mod_func + +_AnyURL: TypeAlias = URLPattern | URLResolver # noqa: PYI047 + +__all__ = [ + "LocalePrefixPattern", + "NoReverseMatch", + "Resolver404", + "ResolverMatch", + "URLPattern", + "URLResolver", + "clear_script_prefix", + "clear_url_caches", + "get_callable", + "get_mod_func", + "get_ns_resolver", + "get_resolver", + "get_script_prefix", + "get_urlconf", + "include", + "is_valid_path", + "path", + "re_path", + "register_converter", + "resolve", + "reverse", + "reverse_lazy", + "set_script_prefix", + "set_urlconf", + "translate_url", +] diff --git a/django-stubs/urls/base.pyi b/django-stubs/urls/base.pyi index 3aaa64790..6c1ce9a49 100644 --- a/django-stubs/urls/base.pyi +++ b/django-stubs/urls/base.pyi @@ -1,40 +1,44 @@ from collections.abc import Callable, Mapping, Sequence -from typing import Any, TypeAlias +from typing import Any, Literal, TypeAlias from django.http.request import QueryDict +from django.http.response import HttpResponseBase from django.urls.resolvers import ResolverMatch +from django.utils.functional import _StrPromise -# The values are passed through `str()` (unless they are bytes), so anything is valid. +# https://github.com/python/typeshed/blob/87f599dc8312ac67b941b5f2b47274534a1a2d3a/stdlib/urllib/parse.pyi#L136-L138 _QueryType: TypeAlias = ( - Mapping[str, object] - | Mapping[bytes, object] - | Mapping[str | bytes, object] - | Mapping[str, Sequence[object]] - | Mapping[bytes, Sequence[object]] - | Mapping[str | bytes, Sequence[object]] - | Sequence[tuple[str | bytes, object]] - | Sequence[tuple[str | bytes, Sequence[object]]] + Mapping[Any, Any] | Mapping[Any, Sequence[Any]] | Sequence[tuple[Any, Any]] | Sequence[tuple[Any, Sequence[Any]]] ) -def resolve(path: str, urlconf: str | None = ...) -> ResolverMatch: ... +def resolve(path: str | _StrPromise, urlconf: str | None = None) -> ResolverMatch: ... + +# NOTE: make sure `reverse` and `reverse_lazy` objects are in sync: def reverse( - viewname: Callable[..., Any] | str | None, - urlconf: str | None = ..., - args: Sequence[Any] | None = ..., - kwargs: dict[str, Any] | None = ..., - current_app: str | None = ..., + viewname: Callable[..., HttpResponseBase] | str | None, + urlconf: str | None = None, + args: Sequence[Any] | None = None, + kwargs: dict[str, Any] | None = None, + current_app: str | None = None, *, - query: QueryDict | _QueryType | None = ..., - fragment: str | None = ..., + query: QueryDict | _QueryType | None = None, + fragment: str | None = None, ) -> str: ... - -reverse_lazy: Any - +def reverse_lazy( + viewname: Callable[..., HttpResponseBase] | str | None, + urlconf: str | None = None, + args: Sequence[Any] | None = None, + kwargs: dict[str, Any] | None = None, + current_app: str | None = None, + *, + query: QueryDict | _QueryType | None = None, + fragment: str | None = None, +) -> _StrPromise: ... def clear_url_caches() -> None: ... def set_script_prefix(prefix: str) -> None: ... def get_script_prefix() -> str: ... def clear_script_prefix() -> None: ... -def set_urlconf(urlconf_name: type[Any] | str | None) -> None: ... -def get_urlconf(default: None = ...) -> type[Any] | str | None: ... -def is_valid_path(path: str, urlconf: str | None = ...) -> bool: ... +def set_urlconf(urlconf_name: str | None) -> None: ... +def get_urlconf(default: str | None = None) -> str | None: ... +def is_valid_path(path: str, urlconf: str | None = None) -> Literal[False] | ResolverMatch: ... def translate_url(url: str, lang_code: str) -> str: ... diff --git a/django-stubs/urls/conf.pyi b/django-stubs/urls/conf.pyi index 207276f73..0aa55d9f6 100644 --- a/django-stubs/urls/conf.pyi +++ b/django-stubs/urls/conf.pyi @@ -1,57 +1,67 @@ -from collections.abc import Callable, Coroutine +from collections.abc import Callable, Coroutine, Sequence +from types import ModuleType from typing import Any, TypeAlias, overload +from django.urls import URLPattern, URLResolver, _AnyURL from django.utils.functional import _StrOrPromise -from ..conf.urls import IncludedURLConf from ..http.response import HttpResponseBase -from .resolvers import URLPattern, URLResolver -_ResponseType: TypeAlias = HttpResponseBase | Coroutine[Any, Any, HttpResponseBase] | Coroutine[Any, Any, None] +_URLConf: TypeAlias = str | ModuleType | Sequence[_AnyURL] +_IncludedURLConf: TypeAlias = tuple[Sequence[URLResolver | URLPattern], str | None, str | None] -def include(arg: Any, namespace: str | None = ...) -> tuple[list[URLResolver], str | None, str | None]: ... +def include(arg: _URLConf | tuple[_URLConf, str], namespace: str | None = None) -> _IncludedURLConf: ... # path() @overload def path( route: _StrOrPromise, - view: Callable[..., _ResponseType], - kwargs: dict[str, Any] = ..., - name: str = ..., + view: Callable[..., HttpResponseBase], + kwargs: dict[str, Any] | None = None, + name: str | None = None, ) -> URLPattern: ... @overload -def path(route: _StrOrPromise, view: IncludedURLConf, kwargs: dict[str, Any] = ..., name: str = ...) -> URLResolver: ... -@overload def path( route: _StrOrPromise, - view: list[URLResolver | str], - kwargs: dict[str, Any] = ..., - name: str = ..., + view: Callable[..., Coroutine[Any, Any, HttpResponseBase]], + kwargs: dict[str, Any] | None = None, + name: str | None = None, +) -> URLPattern: ... +@overload +def path( + route: _StrOrPromise, view: _IncludedURLConf, kwargs: dict[str, Any] | None = None, name: str | None = None ) -> URLResolver: ... @overload def path( route: _StrOrPromise, - view: tuple[list[URLResolver | URLPattern], str, str], - kwargs: dict[str, Any] = ..., - name: str = ..., + view: Sequence[URLResolver | str], + kwargs: dict[str, Any] | None = None, + name: str | None = None, ) -> URLResolver: ... # re_path() @overload def re_path( route: _StrOrPromise, - view: Callable[..., _ResponseType], - kwargs: dict[str, Any] = ..., - name: str = ..., + view: Callable[..., HttpResponseBase], + kwargs: dict[str, Any] | None = None, + name: str | None = None, +) -> URLPattern: ... +@overload +def re_path( + route: _StrOrPromise, + view: Callable[..., Coroutine[Any, Any, HttpResponseBase]], + kwargs: dict[str, Any] | None = None, + name: str | None = None, ) -> URLPattern: ... @overload def re_path( - route: _StrOrPromise, view: IncludedURLConf, kwargs: dict[str, Any] = ..., name: str = ... + route: _StrOrPromise, view: _IncludedURLConf, kwargs: dict[str, Any] | None = None, name: str | None = None ) -> URLResolver: ... @overload def re_path( route: _StrOrPromise, - view: list[URLResolver | str], - kwargs: dict[str, Any] = ..., - name: str = ..., + view: Sequence[URLResolver | str], + kwargs: dict[str, Any] | None = None, + name: str | None = None, ) -> URLResolver: ... diff --git a/django-stubs/urls/converters.pyi b/django-stubs/urls/converters.pyi index 2a3bf7675..3091bfcb8 100644 --- a/django-stubs/urls/converters.pyi +++ b/django-stubs/urls/converters.pyi @@ -1,27 +1,33 @@ -from typing import Any +from typing import Any, Protocol, type_check_only from uuid import UUID +@type_check_only +class _Converter(Protocol): + regex: str + def __init__(self) -> None: ... + def to_python(self, value: str) -> Any: ... + def to_url(self, value: Any) -> str: ... + class IntConverter: - regex: str = ... + regex: str def to_python(self, value: str) -> int: ... def to_url(self, value: str | int) -> str: ... class StringConverter: - regex: str = ... + regex: str def to_python(self, value: str) -> str: ... def to_url(self, value: str) -> str: ... class UUIDConverter: - regex: str = ... + regex: str def to_python(self, value: str) -> UUID: ... def to_url(self, value: str | UUID) -> str: ... class SlugConverter(StringConverter): ... class PathConverter(StringConverter): ... -DEFAULT_CONVERTERS: dict[str, Any] -REGISTERED_CONVERTERS: dict[str, Any] +DEFAULT_CONVERTERS: dict[str, _Converter] +REGISTERED_CONVERTERS: dict[str, _Converter] -def register_converter(converter: type[Any], type_name: str) -> None: ... -def get_converters() -> dict[str, Any]: ... -def get_converter(raw_converter: str) -> Any: ... +def register_converter(converter: type[_Converter], type_name: str) -> None: ... +def get_converters() -> dict[str, _Converter]: ... diff --git a/django-stubs/urls/resolvers.pyi b/django-stubs/urls/resolvers.pyi index df31c11df..157dd265d 100644 --- a/django-stubs/urls/resolvers.pyi +++ b/django-stubs/urls/resolvers.pyi @@ -1,116 +1,138 @@ -from collections.abc import Callable -from typing import Any +from collections.abc import Callable, Iterator, Sequence +from re import Pattern +from types import ModuleType +from typing import Any, TypeAlias, overload -from django.urls.converters import UUIDConverter +from django.core.checks.messages import CheckMessage +from django.http import HttpRequest, HttpResponse +from django.urls import _AnyURL from django.utils.datastructures import MultiValueDict +from django.utils.functional import cached_property class ResolverMatch: - func: Callable[..., Any] = ... - args: tuple[Any, ...] = ... - kwargs: dict[str, Any] = ... - url_name: str | None = ... - app_names: list[str] = ... - app_name: str = ... - namespaces: list[str] = ... - namespace: str = ... - view_name: str = ... - route: str = ... + func: Callable[..., Any] + args: tuple[Any, ...] + kwargs: dict[str, Any] + url_name: str | None + app_names: list[str] + app_name: str + namespaces: list[str] + namespace: str + view_name: str + route: str + tried: Any | None + _func_path: str def __init__( self, func: Callable[..., Any], args: tuple[Any, ...], kwargs: dict[str, Any], - url_name: str | None = ..., - app_names: list[str | None] | None = ..., - namespaces: list[str | None] | None = ..., - route: str | None = ..., + url_name: str | None = None, + app_names: list[str | None] | None = None, + namespaces: list[str | None] | None = None, + route: str | None = None, + tried: Any | None = None, + captured_kwargs: dict[str, Any] | None = None, + extra_kwargs: dict[str, Any] | None = None, ) -> None: ... def __getitem__(self, index: int) -> Any: ... - # for tuple unpacking - def __iter__(self) -> Any: ... + # for tuple unpacking -- python/mypy#2220 + def __iter__(self) -> Iterator[Any]: ... -def get_resolver(urlconf: str | None = ...) -> URLResolver: ... +def get_resolver(urlconf: str | None = None) -> URLResolver: ... def get_ns_resolver(ns_pattern: str, resolver: URLResolver, converters: tuple[Any, ...]) -> URLResolver: ... +_Pattern: TypeAlias = RegexPattern | RoutePattern | LocalePrefixPattern + class LocaleRegexDescriptor: - attr: str = ... - def __init__(self, attr: Any) -> None: ... - def __get__(self, instance: RegexPattern | None, cls: type[RegexPattern] = ...) -> LocaleRegexDescriptor: ... + @overload + def __get__(self, instance: None, cls: type[_Pattern] | None = None) -> LocaleRegexDescriptor: ... + @overload + def __get__(self, instance: _Pattern, cls: type[_Pattern] | None = None) -> Pattern[str]: ... class CheckURLMixin: def describe(self) -> str: ... class RegexPattern(CheckURLMixin): - regex: Any = ... - name: str | None = ... - converters: dict[Any, Any] = ... - def __init__(self, regex: str, name: str | None = ..., is_endpoint: bool = ...) -> None: ... + regex: LocaleRegexDescriptor + name: str | None + converters: dict[str, Any] + def __init__(self, regex: str, name: str | None = None, is_endpoint: bool = False) -> None: ... def match(self, path: str) -> tuple[str, tuple[Any, ...], dict[str, str]] | None: ... - def check(self) -> list[Warning]: ... + def check(self) -> list[CheckMessage]: ... + +whitespace_set: frozenset[str] + +class LocaleRegexRouteDescriptor: + def __get__(self, instance: RoutePattern | None, cls: type | None = None) -> Pattern[str]: ... class RoutePattern(CheckURLMixin): - regex: Any = ... - name: str | None = ... - converters: dict[str, UUIDConverter] = ... - def __init__(self, route: str, name: str | None = ..., is_endpoint: bool = ...) -> None: ... + regex: LocaleRegexRouteDescriptor + name: str | None + converters: dict[str, Any] + def __init__(self, route: str, name: str | None = None, is_endpoint: bool = False) -> None: ... def match(self, path: str) -> tuple[str, tuple[Any, ...], dict[str, int | str]] | None: ... - def check(self) -> list[Warning]: ... + def check(self) -> list[CheckMessage]: ... class LocalePrefixPattern: - prefix_default_language: bool = ... - converters: dict[Any, Any] = ... - def __init__(self, prefix_default_language: bool = ...) -> None: ... + prefix_default_language: bool + converters: dict[str, Any] + def __init__(self, prefix_default_language: bool = True) -> None: ... @property - def regex(self) -> Any: ... + def regex(self) -> Pattern[str]: ... @property def language_prefix(self) -> str: ... def match(self, path: str) -> tuple[str, tuple[Any, ...], dict[str, Any]] | None: ... - def check(self) -> list[Any]: ... + def check(self) -> list[CheckMessage]: ... def describe(self) -> str: ... class URLPattern: - lookup_str: str - pattern: Any = ... - callback: Callable[..., Any] = ... - default_args: dict[str, str] | None = ... - name: str | None = ... + pattern: _Pattern + callback: Callable[..., Any] + default_args: dict[str, Any] + name: str | None def __init__( self, - pattern: Any, + pattern: _Pattern, callback: Callable[..., Any], - default_args: dict[str, str] | None = ..., - name: str | None = ..., + default_args: dict[str, Any] | None = None, + name: str | None = None, ) -> None: ... - def check(self) -> list[Warning]: ... + def check(self) -> list[CheckMessage]: ... def resolve(self, path: str) -> ResolverMatch | None: ... + @cached_property + def lookup_str(self) -> str: ... class URLResolver: - url_patterns: list[URLPattern | URLResolver] - urlconf_module: list[tuple[str, Callable[..., Any]]] | None - pattern: Any = ... - urlconf_name: str | None = ... - callback: None = ... - default_kwargs: dict[str, Any] = ... - namespace: str | None = ... - app_name: str | None = ... + pattern: _Pattern + urlconf_name: str | Sequence[_AnyURL] | ModuleType + callback: None + default_kwargs: dict[str, Any] + namespace: str | None + app_name: str | None _local: Any - _reverse_dict: MultiValueDict[Any, Any] + _reverse_dict: MultiValueDict def __init__( self, - pattern: Any, - urlconf_name: str | None, - default_kwargs: dict[str, Any] | None = ..., - app_name: str | None = ..., - namespace: str | None = ..., + pattern: _Pattern, + urlconf_name: str | Sequence[_AnyURL] | ModuleType, + default_kwargs: dict[str, Any] | None = None, + app_name: str | None = None, + namespace: str | None = None, ) -> None: ... @property - def reverse_dict(self) -> MultiValueDict[Any, Any]: ... + def reverse_dict(self) -> MultiValueDict: ... @property def namespace_dict(self) -> dict[str, tuple[str, URLResolver]]: ... @property def app_dict(self) -> dict[str, list[str]]: ... + @cached_property + def urlconf_module(self) -> ModuleType | None | Sequence[_AnyURL]: ... + @cached_property + def url_patterns(self) -> list[_AnyURL]: ... + def check(self) -> list[CheckMessage]: ... + def _populate(self) -> None: ... + def _is_callback(self, name: str) -> bool: ... def resolve(self, path: str) -> ResolverMatch: ... - def resolve_error_handler(self, view_type: int) -> tuple[Callable[..., Any], dict[str, Any]]: ... + def resolve_error_handler(self, view_type: int) -> Callable[[HttpRequest], HttpResponse]: ... def reverse(self, lookup_view: str, *args: Any, **kwargs: Any) -> str: ... - def _is_callback(self, name: str) -> bool: ... - def _populate(self) -> None: ... diff --git a/s/sync b/s/sync index c628a7bbf..a3b35f521 100755 --- a/s/sync +++ b/s/sync @@ -2,53 +2,107 @@ set -e -# Sync script to update django-stubs files from upstream django-stubs repository -# Reads files to sync from s/sync-files.txt (one file per line) +# Sync the paths listed below from the upstream django-stubs repository +# Comment out any paths that should not be synced. # Usage: uv run s/sync DJANGO_STUBS_TARGET_TAG="6.0.7" -git fetch https://github.com/typeddjango/django-stubs.git $DJANGO_STUBS_TARGET_TAG -git checkout $DJANGO_STUBS_TARGET_TAG -- \ - django-stubs/tasks/ \ - django-stubs/core/cache/ +SYNC_PATHS=( + django-stubs/tasks/ + django-stubs/urls/ + django-stubs/core/cache/ + django-stubs/conf/locale + django-stubs/conf/urls -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -SYNC_FILES="$SCRIPT_DIR/sync-files.txt" -UPSTREAM_BASE_URL="https://raw.githubusercontent.com/typeddjango/django-stubs/refs/tags/${DJANGO_STUBS_TARGET_TAG}" + django-stubs/utils/translation/__init__.pyi + django-stubs/views/__init__.pyi + django-stubs/views/debug.pyi + django-stubs/views/csrf.pyi + django-stubs/views/defaults.pyi + django-stubs/views/i18n.pyi + django-stubs/views/static.pyi + django-stubs/views/decorators/__init__.pyi + django-stubs/views/decorators/cache.pyi + django-stubs/views/decorators/clickjacking.pyi + # django-stubs/views/decorators/csrf.pyi + django-stubs/views/decorators/debug.pyi + # django-stubs/views/decorators/gzip.pyi + # django-stubs/views/decorators/http.pyi + django-stubs/views/decorators/vary.pyi + # django-stubs/http/request.pyi + # django-stubs/contrib/sitemaps/views.pyi + django-stubs/contrib/sitemaps/__init__.pyi + django-stubs/contrib/sitemaps/apps.pyi + django-stubs/contrib/gis/sitemaps/kml.pyi + django-stubs/contrib/flatpages/sitemaps.pyi + # django-stubs/contrib/auth/forms.pyi + django-stubs/contrib/auth/decorators.pyi + django-stubs/core/validators.pyi + # django-stubs/utils/deconstruct.pyi + django-stubs/utils/decorators.pyi + django-stubs/db/models/__init__.pyi + # django-stubs/db/models/query.pyi + django-stubs/db/models/constraints.pyi + # django-stubs/db/models/aggregates.pyi + # django-stubs/db/models/sql/compiler.pyi + # django-stubs/db/models/sql/query.pyi + # django-stubs/db/models/sql/subqueries.pyi + django-stubs/db/models/sql/__init__.pyi + # django-stubs/db/models/sql/where.pyi + django-stubs/db/models/sql/constants.pyi + django-stubs/db/models/sql/datastructures.pyi + django-stubs/db/models/functions/__init__.pyi + # django-stubs/db/models/functions/json.pyi + # django-stubs/db/models/functions/datetime.pyi + django-stubs/db/models/functions/math.pyi + # django-stubs/db/models/functions/comparison.pyi + # django-stubs/db/models/functions/text.pyi + django-stubs/db/__init__.pyi + django-stubs/db/migrations/executor.pyi + django-stubs/core/exceptions.pyi + django-stubs/test/runner.pyi + django-stubs/test/utils.pyi + django-stubs/utils/choices.pyi + # django-stubs/forms/models.pyi + django-stubs/forms/utils.pyi + django-stubs/forms/fields.pyi + django-stubs/forms/__init__.pyi + django-stubs/forms/boundfield.pyi + # django-stubs/forms/forms.pyi + django-stubs/forms/formsets.pyi + django-stubs/forms/renderers.pyi + # django-stubs/forms/widgets.pyi + # django-stubs/utils/datastructures.pyi + django-stubs/contrib/admin/decorators.pyi + # django-stubs/contrib/admin/options.pyi + django-stubs/contrib/contenttypes/admin.pyi + django-stubs/contrib/sites/admin.pyi + django-stubs/contrib/redirects/admin.pyi + django-stubs/contrib/flatpages/admin.pyi + # django-stubs/template/response.pyi + django-stubs/template/backends/base.pyi + django-stubs/template/context.pyi + django-stubs/template/exceptions.pyi + django-stubs/template/library.pyi + django-stubs/template/loader.pyi + django-stubs/utils/safestring.pyi + django-stubs/middleware/csp.pyi + django-stubs/utils/csp.pyi + django-stubs/contrib/admin/tests.pyi + # django-stubs/utils/html.pyi + django-stubs/core/signing.pyi + django-stubs/contrib/gis/geoip2.pyi + django-stubs/utils/timezone.pyi + django-stubs/utils/dateformat.pyi + django-stubs/templatetags/tz.pyi +) -if [ ! -f "$SYNC_FILES" ]; then - echo "Error: $SYNC_FILES not found" - exit 1 +if [ "${#SYNC_PATHS[@]}" -gt 0 ]; then + git fetch https://github.com/typeddjango/django-stubs.git "$DJANGO_STUBS_TARGET_TAG" + # Preserve staged changes and local files absent from upstream. + git restore --source="$DJANGO_STUBS_TARGET_TAG" --worktree --overlay -- "${SYNC_PATHS[@]}" fi -while IFS= read -r file || [ -n "$file" ]; do - # Skip empty lines and comments - [[ -z "$file" || "$file" == \#* ]] && continue - # Normalize path (remove leading ./ if present) - file="${file#./}" - - # Check if file path starts with django-stubs/ - if [[ ! "$file" == django-stubs/* ]]; then - echo "Error: File path must start with 'django-stubs/': $file" - exit 1 - fi - - url="${UPSTREAM_BASE_URL}/${file}" - - echo "Fetching: $url" - - # Create directory if it doesn't exist - mkdir -p "$(dirname "$file")" - - # Download the file - if curl -fsSL "$url" -o "$file"; then - echo "Updated: $file" - else - echo "Error: Failed to fetch $file from upstream" - exit 1 - fi -done < "$SYNC_FILES" - uv run ruff format tests django-stubs uv run ruff check --fix diff --git a/s/sync-files.txt b/s/sync-files.txt deleted file mode 100644 index 6546ce1d5..000000000 --- a/s/sync-files.txt +++ /dev/null @@ -1,81 +0,0 @@ -django-stubs/utils/translation/__init__.pyi -django-stubs/views/__init__.pyi -django-stubs/views/debug.pyi -django-stubs/views/csrf.pyi -django-stubs/views/defaults.pyi -django-stubs/views/i18n.pyi -django-stubs/views/static.pyi -django-stubs/views/decorators/__init__.pyi -django-stubs/views/decorators/cache.pyi -django-stubs/views/decorators/clickjacking.pyi -#django-stubs/views/decorators/csrf.pyi -django-stubs/views/decorators/debug.pyi -#django-stubs/views/decorators/gzip.pyi -#django-stubs/views/decorators/http.pyi -django-stubs/views/decorators/vary.pyi -#django-stubs/http/request.pyi -#django-stubs/contrib/sitemaps/views.pyi -django-stubs/contrib/sitemaps/__init__.pyi -django-stubs/contrib/sitemaps/apps.pyi -django-stubs/contrib/gis/sitemaps/kml.pyi -django-stubs/contrib/flatpages/sitemaps.pyi -#django-stubs/contrib/auth/forms.pyi -django-stubs/contrib/auth/decorators.pyi -django-stubs/core/validators.pyi -#django-stubs/utils/deconstruct.pyi -django-stubs/utils/decorators.pyi -django-stubs/db/models/__init__.pyi -#django-stubs/db/models/query.pyi -django-stubs/db/models/constraints.pyi -#django-stubs/db/models/aggregates.pyi -#django-stubs/db/models/sql/compiler.pyi -#django-stubs/db/models/sql/query.pyi -#django-stubs/db/models/sql/subqueries.pyi -django-stubs/db/models/sql/__init__.pyi -#django-stubs/db/models/sql/where.pyi -django-stubs/db/models/sql/constants.pyi -django-stubs/db/models/sql/datastructures.pyi -django-stubs/db/models/functions/__init__.pyi -#django-stubs/db/models/functions/json.pyi -#django-stubs/db/models/functions/datetime.pyi -django-stubs/db/models/functions/math.pyi -#django-stubs/db/models/functions/comparison.pyi -#django-stubs/db/models/functions/text.pyi -django-stubs/db/__init__.pyi -django-stubs/db/migrations/executor.pyi -django-stubs/core/exceptions.pyi -django-stubs/test/runner.pyi -django-stubs/test/utils.pyi -django-stubs/utils/choices.pyi -#django-stubs/forms/models.pyi -django-stubs/forms/utils.pyi -django-stubs/forms/fields.pyi -django-stubs/forms/__init__.pyi -django-stubs/forms/boundfield.pyi -#django-stubs/forms/forms.pyi -django-stubs/forms/formsets.pyi -django-stubs/forms/renderers.pyi -#django-stubs/forms/widgets.pyi -#django-stubs/utils/datastructures.pyi -django-stubs/contrib/admin/decorators.pyi -#django-stubs/contrib/admin/options.pyi -django-stubs/contrib/contenttypes/admin.pyi -django-stubs/contrib/sites/admin.pyi -django-stubs/contrib/redirects/admin.pyi -django-stubs/contrib/flatpages/admin.pyi -#django-stubs/template/response.pyi -django-stubs/template/backends/base.pyi -django-stubs/template/context.pyi -django-stubs/template/exceptions.pyi -django-stubs/template/library.pyi -django-stubs/template/loader.pyi -django-stubs/utils/safestring.pyi -django-stubs/middleware/csp.pyi -django-stubs/utils/csp.pyi -django-stubs/contrib/admin/tests.pyi -#django-stubs/utils/html.pyi -django-stubs/core/signing.pyi -django-stubs/contrib/gis/geoip2.pyi -django-stubs/utils/timezone.pyi -django-stubs/utils/dateformat.pyi -django-stubs/templatetags/tz.pyi