Skip to content

Commit 27bb147

Browse files
Fix @deprecated based on the review (#2485)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4154c18 commit 27bb147

File tree

12 files changed

+25
-17
lines changed

12 files changed

+25
-17
lines changed

django-stubs/contrib/admin/options.pyi

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import enum
22
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
3-
from typing import Any, Generic, Literal, TypeVar, cast, type_check_only
3+
from typing import Any, Generic, Literal, TypeVar, cast, overload, type_check_only
44

55
from django import forms
66
from django.contrib.admin.filters import FieldListFilter, ListFilter
@@ -129,8 +129,11 @@ class BaseModelAdmin(Generic[_ModelT]):
129129
def get_prepopulated_fields(self, request: HttpRequest, obj: _ModelT | None = ...) -> dict[str, Sequence[str]]: ...
130130
def get_queryset(self, request: HttpRequest) -> QuerySet[_ModelT]: ...
131131
def get_sortable_by(self, request: HttpRequest) -> _DisplayT[_ModelT]: ...
132-
@deprecated("The None value for the request parameter will be removed in Django 6.0.")
133-
def lookup_allowed(self, lookup: str, value: str, request: HttpRequest | None = ...) -> bool: ...
132+
@overload
133+
@deprecated("None value for the request parameter will be removed in Django 6.0.")
134+
def lookup_allowed(self, lookup: str, value: str, request: None = None) -> bool: ...
135+
@overload
136+
def lookup_allowed(self, lookup: str, value: str, request: HttpRequest) -> bool: ...
134137
def to_field_allowed(self, request: HttpRequest, to_field: str) -> bool: ...
135138
def has_add_permission(self, request: HttpRequest) -> bool: ...
136139
def has_change_permission(self, request: HttpRequest, obj: _ModelT | None = ...) -> bool: ...

django-stubs/contrib/gis/geoip2/base.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ class GeoIP2:
2929
def is_city(self) -> bool: ...
3030
@cached_property
3131
def is_country(self) -> bool: ...
32-
@deprecated("The coords() is deprecated and will be removed in Django 6.0. Use lon_lat() instead.")
32+
@deprecated("coords() is deprecated and will be removed in Django 6.0. Use lon_lat() instead.")
3333
def coords(self, query: str, ordering: Sequence[str] = ...) -> tuple[float, float] | tuple[None, None]: ...
3434
def lon_lat(self, query: str) -> tuple[float, float] | tuple[None, None]: ...
3535
def lat_lon(self, query: str) -> tuple[float, float] | tuple[None, None]: ...
3636
def geos(self, query: str) -> Point: ...
3737
@property
3838
def info(self) -> str: ...
3939
@classmethod
40-
@deprecated("The open() is deprecated and will be removed in Django 6.0. Use GeoIP2() instead.")
40+
@deprecated("open() is deprecated and will be removed in Django 6.0. Use GeoIP2() instead.")
4141
def open(cls, full_path: Path | str | None, cache: int) -> Any: ...

django-stubs/db/backends/base/operations.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class BaseDatabaseOperations:
4545
def deferrable_sql(self) -> str: ...
4646
def distinct_sql(self, fields: list[str], params: list[Any] | None) -> tuple[list[str], list[str]]: ...
4747
def fetch_returned_insert_columns(self, cursor: Any, returning_params: Any) -> Any: ...
48-
@deprecated("The field_cast_sql() is deprecated and will be removed in Django 6.0. Use lookup_cast() instead.")
48+
@deprecated("field_cast_sql() is deprecated and will be removed in Django 6.0. Use lookup_cast() instead.")
4949
def field_cast_sql(self, db_type: str | None, internal_type: str) -> str: ...
5050
def force_no_ordering(self) -> list[Any]: ...
5151
def for_update_sql(

django-stubs/db/models/constraints.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class CheckConstraint(BaseConstraint):
4747
condition: Q | BaseExpression
4848

4949
@overload
50-
@deprecated("The check keyword argument is deprecated in favor of condition and will be removed in Django 6.0")
50+
@deprecated("check keyword argument is deprecated in favor of condition and will be removed in Django 6.0")
5151
def __init__(
5252
self,
5353
*,

django-stubs/db/models/enums.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from typing import Any, TypeVar, overload, type_check_only
44

55
from _typeshed import ConvertibleToInt
66
from django.utils.functional import _StrOrPromise
7-
from typing_extensions import TypeAlias, deprecated
7+
from typing_extensions import deprecated
88

99
_Self = TypeVar("_Self")
1010

@@ -21,8 +21,7 @@ else:
2121
class IntEnum(int, ReprEnum): ... # type: ignore[misc]
2222
class StrEnum(str, ReprEnum): ... # type: ignore[misc]
2323

24-
@deprecated("ChoicesMeta is deprecated in favor of ChoicesType and will be removed in Django 6.0.")
25-
class ChoicesMeta(EnumType):
24+
class ChoicesType(EnumType):
2625
# There's a contradiction between mypy and PYI019 regarding metaclasses. Where mypy
2726
# disallows 'typing_extensions.Self' on metaclasses, while PYI019 try to enforce
2827
# 'typing_extensions.Self' for '__new__' methods.. We've chosen to ignore the
@@ -40,7 +39,8 @@ class ChoicesMeta(EnumType):
4039
@property
4140
def values(self) -> list[Any]: ...
4241

43-
ChoicesType: TypeAlias = ChoicesMeta
42+
@deprecated("ChoicesMeta is deprecated in favor of ChoicesType and will be removed in Django 6.0.")
43+
class ChoicesMeta(ChoicesType): ...
4444

4545
class Choices(enum.Enum, metaclass=ChoicesType): # type: ignore[misc]
4646
@property

django-stubs/db/models/fields/mixins.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ NOT_PROVIDED: Any
99
class FieldCacheMixin:
1010
def get_cache_name(self) -> str: ...
1111
@cached_property
12-
@deprecated("The cache_name() is deprecated and will be removed in Django 6.0. Use get_cache_name() instead.")
12+
@deprecated("cache_name() is deprecated and will be removed in Django 6.0. Use get_cache_name() instead.")
1313
def cache_name(self) -> str: ...
1414
def get_cached_value(self, instance: Model, default: Any = ...) -> Model | None: ...
1515
def is_cached(self, instance: Model) -> bool: ...

django-stubs/db/models/fields/reverse_related.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ForeignObjectRel(FieldCacheMixin):
7979
) -> _ChoicesList: ...
8080
def is_hidden(self) -> bool: ...
8181
@deprecated(
82-
"The get_joining_columns() is deprecated and will be removed in Django 6.0. Use get_joining_fields() instead."
82+
"get_joining_columns() is deprecated and will be removed in Django 6.0. Use get_joining_fields() instead."
8383
)
8484
def get_joining_columns(self) -> tuple: ...
8585
def get_joining_fields(self) -> tuple[tuple[Field, Field], ...]: ...

django-stubs/db/models/query.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class Prefetch:
241241
def get_current_prefetch_to(self, level: int) -> str: ...
242242
def get_current_to_attr(self, level: int) -> tuple[str, str]: ...
243243
@deprecated(
244-
"The get_current_queryset() is deprecated and will be removed in Django 6.0. Use get_current_querysets() instead."
244+
"get_current_queryset() is deprecated and will be removed in Django 6.0. Use get_current_querysets() instead."
245245
)
246246
def get_current_queryset(self, level: int) -> QuerySet | None: ...
247247
def get_current_querysets(self, level: int) -> list[QuerySet] | None: ...

django-stubs/forms/renderers.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Jinja2(EngineMixin, BaseRenderer):
3030
def backend(self) -> type[Jinja2R]: ...
3131

3232
@deprecated(
33-
"The Jinja2DivFormRenderer transitional form renderer is deprecated and will be removed in Django 6.0. Use Jinja2 instead."
33+
"Jinja2DivFormRenderer transitional form renderer is deprecated and will be removed in Django 6.0. Use Jinja2 instead."
3434
)
3535
class Jinja2DivFormRenderer(Jinja2):
3636
form_template_name: str

django-stubs/utils/html.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from functools import cached_property
33
from html.parser import HTMLParser
44
from json import JSONEncoder
55
from re import Pattern
6-
from typing import Any
6+
from typing import Any, overload
77

88
from _typeshed import Incomplete
99
from django.utils.functional import SimpleLazyObject, _StrOrPromise
@@ -20,7 +20,10 @@ def json_script(value: Any, element_id: str | None = None, encoder: type[JSONEnc
2020

2121
# conditional_escape could use a protocol to be more precise, see https://github.com/typeddjango/django-stubs/issues/1474
2222
def conditional_escape(text: _StrOrPromise | SafeData) -> SafeString: ...
23+
@overload
2324
@deprecated("Calling format_html() without passing args or kwargs is deprecated.")
25+
def format_html(format_string: str) -> SafeString: ...
26+
@overload
2427
def format_html(format_string: str, *args: Any, **kwargs: Any) -> SafeString: ...
2528
def format_html_join(sep: str, format_string: str, args_generator: Iterable[Iterable[Any]]) -> SafeString: ...
2629
def linebreaks(value: Any, autoescape: bool = False) -> str: ...

0 commit comments

Comments
 (0)