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

Fix @deprecated based on the review #2485

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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: 6 additions & 3 deletions django-stubs/contrib/admin/options.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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: ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/gis/geoip2/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ 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]: ...
def geos(self, query: str) -> Point: ...
@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: ...
2 changes: 1 addition & 1 deletion django-stubs/db/backends/base/operations.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/models/constraints.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
*,
Expand Down
8 changes: 4 additions & 4 deletions django-stubs/db/models/enums.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/models/fields/mixins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/models/fields/reverse_related.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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], ...]: ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/models/query.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/forms/renderers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion django-stubs/utils/html.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/utils/itercompat.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
2 changes: 2 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading