diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index 02e172dc0..1728034d0 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -1,6 +1,6 @@ import enum from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence -from typing import Any, Generic, Literal, TypeVar, cast, type_check_only +from typing import Any, Generic, Literal, TypeVar, cast, overload, type_check_only from django import forms from django.contrib.admin.filters import FieldListFilter, ListFilter @@ -129,8 +129,11 @@ class BaseModelAdmin(Generic[_ModelT]): def get_prepopulated_fields(self, request: HttpRequest, obj: _ModelT | None = ...) -> dict[str, Sequence[str]]: ... def get_queryset(self, request: HttpRequest) -> QuerySet[_ModelT]: ... def get_sortable_by(self, request: HttpRequest) -> _DisplayT[_ModelT]: ... - @deprecated("The None value for the request parameter will be removed in Django 6.0.") - def lookup_allowed(self, lookup: str, value: str, request: HttpRequest | None = ...) -> bool: ... + @overload + @deprecated("None value for the request parameter will be removed in Django 6.0.") + def lookup_allowed(self, lookup: str, value: str, request: None = None) -> bool: ... + @overload + def lookup_allowed(self, lookup: str, value: str, request: HttpRequest) -> bool: ... def to_field_allowed(self, request: HttpRequest, to_field: str) -> bool: ... def has_add_permission(self, request: HttpRequest) -> bool: ... def has_change_permission(self, request: HttpRequest, obj: _ModelT | None = ...) -> bool: ... diff --git a/django-stubs/contrib/gis/geoip2/base.pyi b/django-stubs/contrib/gis/geoip2/base.pyi index 3f75eb18c..30b83fa95 100644 --- a/django-stubs/contrib/gis/geoip2/base.pyi +++ b/django-stubs/contrib/gis/geoip2/base.pyi @@ -29,7 +29,7 @@ class GeoIP2: def is_city(self) -> bool: ... @cached_property def is_country(self) -> bool: ... - @deprecated("The coords() is deprecated and will be removed in Django 6.0. Use lon_lat() instead.") + @deprecated("coords() is deprecated and will be removed in Django 6.0. Use lon_lat() instead.") def coords(self, query: str, ordering: Sequence[str] = ...) -> tuple[float, float] | tuple[None, None]: ... def lon_lat(self, query: str) -> tuple[float, float] | tuple[None, None]: ... def lat_lon(self, query: str) -> tuple[float, float] | tuple[None, None]: ... @@ -37,5 +37,5 @@ class GeoIP2: @property def info(self) -> str: ... @classmethod - @deprecated("The open() is deprecated and will be removed in Django 6.0. Use GeoIP2() instead.") + @deprecated("open() is deprecated and will be removed in Django 6.0. Use GeoIP2() instead.") def open(cls, full_path: Path | str | None, cache: int) -> Any: ... diff --git a/django-stubs/db/backends/base/operations.pyi b/django-stubs/db/backends/base/operations.pyi index fc5eac0f8..f08480c92 100644 --- a/django-stubs/db/backends/base/operations.pyi +++ b/django-stubs/db/backends/base/operations.pyi @@ -45,7 +45,7 @@ class BaseDatabaseOperations: def deferrable_sql(self) -> str: ... def distinct_sql(self, fields: list[str], params: list[Any] | None) -> tuple[list[str], list[str]]: ... def fetch_returned_insert_columns(self, cursor: Any, returning_params: Any) -> Any: ... - @deprecated("The field_cast_sql() is deprecated and will be removed in Django 6.0. Use lookup_cast() instead.") + @deprecated("field_cast_sql() is deprecated and will be removed in Django 6.0. Use lookup_cast() instead.") def field_cast_sql(self, db_type: str | None, internal_type: str) -> str: ... def force_no_ordering(self) -> list[Any]: ... def for_update_sql( diff --git a/django-stubs/db/models/constraints.pyi b/django-stubs/db/models/constraints.pyi index e3dd59585..beb69d87f 100644 --- a/django-stubs/db/models/constraints.pyi +++ b/django-stubs/db/models/constraints.pyi @@ -47,7 +47,7 @@ class CheckConstraint(BaseConstraint): condition: Q | BaseExpression @overload - @deprecated("The check keyword argument is deprecated in favor of condition and will be removed in Django 6.0") + @deprecated("check keyword argument is deprecated in favor of condition and will be removed in Django 6.0") def __init__( self, *, diff --git a/django-stubs/db/models/enums.pyi b/django-stubs/db/models/enums.pyi index e511a4f01..64328e0c0 100644 --- a/django-stubs/db/models/enums.pyi +++ b/django-stubs/db/models/enums.pyi @@ -4,7 +4,7 @@ from typing import Any, TypeVar, overload, type_check_only from _typeshed import ConvertibleToInt from django.utils.functional import _StrOrPromise -from typing_extensions import TypeAlias, deprecated +from typing_extensions import deprecated _Self = TypeVar("_Self") @@ -21,8 +21,7 @@ else: class IntEnum(int, ReprEnum): ... # type: ignore[misc] class StrEnum(str, ReprEnum): ... # type: ignore[misc] -@deprecated("ChoicesMeta is deprecated in favor of ChoicesType and will be removed in Django 6.0.") -class ChoicesMeta(EnumType): +class ChoicesType(EnumType): # There's a contradiction between mypy and PYI019 regarding metaclasses. Where mypy # disallows 'typing_extensions.Self' on metaclasses, while PYI019 try to enforce # 'typing_extensions.Self' for '__new__' methods.. We've chosen to ignore the @@ -40,7 +39,8 @@ class ChoicesMeta(EnumType): @property def values(self) -> list[Any]: ... -ChoicesType: TypeAlias = ChoicesMeta +@deprecated("ChoicesMeta is deprecated in favor of ChoicesType and will be removed in Django 6.0.") +class ChoicesMeta(ChoicesType): ... class Choices(enum.Enum, metaclass=ChoicesType): # type: ignore[misc] @property diff --git a/django-stubs/db/models/fields/mixins.pyi b/django-stubs/db/models/fields/mixins.pyi index fe6aaa2af..297d3230d 100644 --- a/django-stubs/db/models/fields/mixins.pyi +++ b/django-stubs/db/models/fields/mixins.pyi @@ -9,7 +9,7 @@ NOT_PROVIDED: Any class FieldCacheMixin: def get_cache_name(self) -> str: ... @cached_property - @deprecated("The cache_name() is deprecated and will be removed in Django 6.0. Use get_cache_name() instead.") + @deprecated("cache_name() is deprecated and will be removed in Django 6.0. Use get_cache_name() instead.") def cache_name(self) -> str: ... def get_cached_value(self, instance: Model, default: Any = ...) -> Model | None: ... def is_cached(self, instance: Model) -> bool: ... diff --git a/django-stubs/db/models/fields/reverse_related.pyi b/django-stubs/db/models/fields/reverse_related.pyi index 2a7961de1..30d23d33c 100644 --- a/django-stubs/db/models/fields/reverse_related.pyi +++ b/django-stubs/db/models/fields/reverse_related.pyi @@ -79,7 +79,7 @@ class ForeignObjectRel(FieldCacheMixin): ) -> _ChoicesList: ... def is_hidden(self) -> bool: ... @deprecated( - "The get_joining_columns() is deprecated and will be removed in Django 6.0. Use get_joining_fields() instead." + "get_joining_columns() is deprecated and will be removed in Django 6.0. Use get_joining_fields() instead." ) def get_joining_columns(self) -> tuple: ... def get_joining_fields(self) -> tuple[tuple[Field, Field], ...]: ... diff --git a/django-stubs/db/models/query.pyi b/django-stubs/db/models/query.pyi index d6d27f213..3cc3fed92 100644 --- a/django-stubs/db/models/query.pyi +++ b/django-stubs/db/models/query.pyi @@ -241,7 +241,7 @@ class Prefetch: def get_current_prefetch_to(self, level: int) -> str: ... def get_current_to_attr(self, level: int) -> tuple[str, str]: ... @deprecated( - "The get_current_queryset() is deprecated and will be removed in Django 6.0. Use get_current_querysets() instead." + "get_current_queryset() is deprecated and will be removed in Django 6.0. Use get_current_querysets() instead." ) def get_current_queryset(self, level: int) -> QuerySet | None: ... def get_current_querysets(self, level: int) -> list[QuerySet] | None: ... diff --git a/django-stubs/forms/renderers.pyi b/django-stubs/forms/renderers.pyi index a4ed0a296..e88459c68 100644 --- a/django-stubs/forms/renderers.pyi +++ b/django-stubs/forms/renderers.pyi @@ -30,7 +30,7 @@ class Jinja2(EngineMixin, BaseRenderer): def backend(self) -> type[Jinja2R]: ... @deprecated( - "The Jinja2DivFormRenderer transitional form renderer is deprecated and will be removed in Django 6.0. Use Jinja2 instead." + "Jinja2DivFormRenderer transitional form renderer is deprecated and will be removed in Django 6.0. Use Jinja2 instead." ) class Jinja2DivFormRenderer(Jinja2): form_template_name: str diff --git a/django-stubs/utils/html.pyi b/django-stubs/utils/html.pyi index 38e059cff..87ddb2df3 100644 --- a/django-stubs/utils/html.pyi +++ b/django-stubs/utils/html.pyi @@ -3,7 +3,7 @@ from functools import cached_property from html.parser import HTMLParser from json import JSONEncoder from re import Pattern -from typing import Any +from typing import Any, overload from _typeshed import Incomplete from django.utils.functional import SimpleLazyObject, _StrOrPromise @@ -20,7 +20,10 @@ def json_script(value: Any, element_id: str | None = None, encoder: type[JSONEnc # conditional_escape could use a protocol to be more precise, see https://github.com/typeddjango/django-stubs/issues/1474 def conditional_escape(text: _StrOrPromise | SafeData) -> SafeString: ... +@overload @deprecated("Calling format_html() without passing args or kwargs is deprecated.") +def format_html(format_string: str) -> SafeString: ... +@overload def format_html(format_string: str, *args: Any, **kwargs: Any) -> SafeString: ... def format_html_join(sep: str, format_string: str, args_generator: Iterable[Iterable[Any]]) -> SafeString: ... def linebreaks(value: Any, autoescape: bool = False) -> str: ... diff --git a/django-stubs/utils/itercompat.pyi b/django-stubs/utils/itercompat.pyi index 379e86037..8023c9e40 100644 --- a/django-stubs/utils/itercompat.pyi +++ b/django-stubs/utils/itercompat.pyi @@ -3,6 +3,6 @@ from typing import Any from typing_extensions import deprecated @deprecated( - "The django.utils.itercompat.is_iterable() is deprecated and will be removed in Django 6.0. Use isinstance(..., collections.abc.Iterable) instead." + "django.utils.itercompat.is_iterable() is deprecated and will be removed in Django 6.0. Use isinstance(..., collections.abc.Iterable) instead." ) def is_iterable(x: Any) -> bool: ... diff --git a/mypy.ini b/mypy.ini index 428791b81..774e0fc2a 100644 --- a/mypy.ini +++ b/mypy.ini @@ -18,6 +18,8 @@ disable_error_code = empty-body force_uppercase_builtins = true force_union_syntax = true +enable_error_code = deprecated + plugins = mypy_django_plugin.main,