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

Update django to 5.1.4, drop black #2455

Merged
merged 4 commits into from
Dec 5, 2024
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
5 changes: 1 addition & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ repos:
hooks:
- id: ruff
args: ["--fix", "--exit-non-zero-on-fix"]
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
- id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
Expand Down
11 changes: 2 additions & 9 deletions django-stubs/contrib/admin/sites.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from collections.abc import Callable, Iterable
from typing import Any, TypeVar
from weakref import WeakSet

from django.apps.config import AppConfig
from django.contrib.admin.models import LogEntry
Expand All @@ -16,14 +16,7 @@ from django.urls import URLPattern, URLResolver
from django.utils.functional import LazyObject, _StrOrPromise
from typing_extensions import TypeAlias

if sys.version_info >= (3, 9):
from weakref import WeakSet

all_sites: WeakSet[AdminSite]
else:
from collections.abc import MutableSet

all_sites: MutableSet[AdminSite]
all_sites: WeakSet[AdminSite]

_ViewType = TypeVar("_ViewType", bound=Callable[..., HttpResponseBase])
_ModelT = TypeVar("_ModelT", bound=Model)
Expand Down
3 changes: 2 additions & 1 deletion django-stubs/contrib/auth/base_user.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, ClassVar, Iterable, Literal, TypeVar, overload
from collections.abc import Iterable
from typing import Any, ClassVar, Literal, TypeVar, overload

from django.db import models
from django.db.models.base import Model
Expand Down
3 changes: 2 additions & 1 deletion django-stubs/contrib/gis/db/backends/postgis/operations.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Literal, MutableMapping
from collections.abc import MutableMapping
from typing import Any, Literal

from django.contrib.gis.db.backends.base.operations import BaseSpatialOperations
from django.contrib.gis.db.backends.utils import SpatialOperator
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/gis/db/backends/utils.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Sequence
from typing import Any, MutableMapping
from collections.abc import MutableMapping, Sequence
from typing import Any

from django.contrib.gis.db.models.lookups import GISLookup
from django.db.backends.base.base import BaseDatabaseWrapper
Expand Down
3 changes: 2 additions & 1 deletion django-stubs/contrib/messages/storage/cookie.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from typing import Any, Callable, Sequence
from collections.abc import Sequence
from typing import Any, Callable

from django.contrib.messages.storage.base import BaseStorage

Expand Down
4 changes: 2 additions & 2 deletions django-stubs/core/cache/backends/redis.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Mapping
from collections.abc import Iterable, Mapping
from datetime import timedelta
from typing import Any, Callable, Iterable, Protocol, SupportsInt, overload, type_check_only
from typing import Any, Callable, Protocol, SupportsInt, overload, type_check_only

from _typeshed import ReadableBuffer
from django.core.cache.backends.base import BaseCache
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/core/handlers/exception.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from django.http.response import HttpResponse, HttpResponseBase
from django.urls.resolvers import URLResolver

def convert_exception_to_response(
get_response: Callable[[HttpRequest], HttpResponseBase | Awaitable[HttpResponseBase]]
get_response: Callable[[HttpRequest], HttpResponseBase | Awaitable[HttpResponseBase]],
) -> Callable[[HttpRequest], HttpResponseBase | Awaitable[HttpResponseBase]]: ...
def response_for_exception(request: HttpRequest, exc: Exception) -> HttpResponse: ...
def get_exception_response(
Expand Down
3 changes: 2 additions & 1 deletion django-stubs/db/models/fields/generated.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, ClassVar, Iterable, Literal
from collections.abc import Iterable
from typing import Any, ClassVar, Literal

from django.core.validators import _ValidatorCallable
from django.db import models
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/db/models/lookups.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Iterable
from typing import Any, Generic, Literal, Sequence, TypeVar
from collections.abc import Iterable, Sequence
from typing import Any, Generic, Literal, TypeVar

from django.core.exceptions import EmptyResultSet
from django.db.backends.base.base import BaseDatabaseWrapper
Expand Down
8 changes: 6 additions & 2 deletions django-stubs/db/models/sql/compiler.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class SQLCompiler:
col_count: int | None
def setup_query(self, with_col_aliases: bool = False) -> None: ...
has_extra_select: Any
def pre_sql_setup(self, with_col_aliases: bool = False) -> tuple[
def pre_sql_setup(
self,
with_col_aliases: bool = False,
) -> tuple[
list[tuple[Expression, _AsSqlType, None]],
list[tuple[Expression, tuple[str, _ParamsT, bool]]],
list[_AsSqlType],
Expand All @@ -48,7 +51,8 @@ class SQLCompiler:
self, expressions: list[Expression], having: list[Expression] | tuple
) -> list[Expression]: ...
def get_select(
self, with_col_aliases: bool = False
self,
with_col_aliases: bool = False,
) -> tuple[list[tuple[Expression, _AsSqlType, str | None]], dict[str, Any] | None, dict[str, int]]: ...
def _order_by_pairs(self) -> None: ...
def get_order_by(self) -> list[tuple[Expression, tuple[str, _ParamsT, bool]]]: ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/http/request.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import datetime
from collections.abc import Iterable, Mapping
from collections.abc import Awaitable, Iterable, Mapping
from io import BytesIO
from re import Pattern
from typing import Any, Awaitable, BinaryIO, Callable, Literal, NoReturn, TypeVar, overload, type_check_only
from typing import Any, BinaryIO, Callable, Literal, NoReturn, TypeVar, overload, type_check_only

from django.contrib.auth.base_user import _UserModel
from django.contrib.auth.models import AnonymousUser
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/urls/conf.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Callable, Sequence
from collections.abc import Callable, Coroutine, Sequence
from types import ModuleType
from typing import Any, Coroutine, overload
from typing import Any, overload

from django.urls import URLPattern, URLResolver, _AnyURL
from django.utils.functional import _StrOrPromise
Expand Down
1 change: 1 addition & 0 deletions django-stubs/utils/html.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ from django.utils.safestring import SafeData, SafeString

VOID_ELEMENTS: frozenset[str]
MAX_URL_LENGTH: int
MAX_STRIP_TAGS_DEPTH: int

def escape(text: Any) -> SafeString: ...
def escapejs(value: Any) -> SafeString: ...
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/utils/timezone.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import zoneinfo
from contextlib import ContextDecorator
from datetime import date, datetime, time, timedelta, timezone, tzinfo
from types import TracebackType
from typing import Literal, overload

import zoneinfo # type: ignore[import-not-found,unused-ignore]

def get_fixed_timezone(offset: timedelta | int) -> timezone: ...
def get_default_timezone() -> zoneinfo.ZoneInfo: ...
def get_default_timezone_name() -> str: ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/views/generic/base.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from collections.abc import Callable, Sequence
from typing import Any, Mapping
from collections.abc import Callable, Mapping, Sequence
from typing import Any

from django.http.request import HttpRequest
from django.http.response import HttpResponse, HttpResponseBase
Expand Down
4 changes: 2 additions & 2 deletions ext/django_stubs_ext/annotations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Generic, Mapping, TypeVar
from collections.abc import Mapping
from typing import Annotated, Any, Generic, TypeVar

from django.db.models.base import Model
from typing_extensions import Annotated

# Really, we would like to use TypedDict as a bound, but it's not possible
_Annotations = TypeVar("_Annotations", covariant=True, bound=Mapping[str, Any])
Expand Down
11 changes: 6 additions & 5 deletions ext/django_stubs_ext/db/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import ClassVar, List, Literal, Sequence, Tuple, Union
from collections.abc import Sequence
from typing import ClassVar, Literal, Union

from django.db.models import BaseConstraint, Index, OrderBy

Expand All @@ -27,16 +28,16 @@ class TypedModelMeta:
managed: ClassVar[bool] # default: True
order_with_respect_to: ClassVar[str]
ordering: ClassVar[Sequence[Union[str, OrderBy]]]
permissions: ClassVar[List[Tuple[str, str]]]
permissions: ClassVar[list[tuple[str, str]]]
default_permissions: ClassVar[Sequence[str]] # default: ("add", "change", "delete", "view")
proxy: ClassVar[bool] # default: False
required_db_features: ClassVar[List[str]]
required_db_features: ClassVar[list[str]]
required_db_vendor: ClassVar[Literal["sqlite", "postgresql", "mysql", "oracle"]]
select_on_save: ClassVar[bool] # default: False
indexes: ClassVar[List[Index]]
indexes: ClassVar[list[Index]]
unique_together: ClassVar[Union[Sequence[Sequence[str]], Sequence[str]]]
index_together: ClassVar[Union[Sequence[Sequence[str]], Sequence[str]]] # Deprecated in Django 4.2
constraints: ClassVar[List[BaseConstraint]]
constraints: ClassVar[list[BaseConstraint]]
verbose_name: ClassVar[StrOrPromise]
verbose_name_plural: ClassVar[StrOrPromise]

Expand Down
8 changes: 4 additions & 4 deletions ext/django_stubs_ext/db/router.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Optional, Type
from typing import TYPE_CHECKING, Optional

if TYPE_CHECKING:
from typing import Any
Expand All @@ -14,11 +14,11 @@ class TypedDatabaseRouter:
Django documentation: https://docs.djangoproject.com/en/stable/topics/db/multi-db/#automatic-database-routing
"""

def db_for_read(self, model: Type[Model], **hints: Any) -> Optional[str]: ...
def db_for_read(self, model: type[Model], **hints: Any) -> Optional[str]: ...

def db_for_write(self, model: Type[Model], **hints: Any) -> Optional[str]: ...
def db_for_write(self, model: type[Model], **hints: Any) -> Optional[str]: ...

def allow_relation(self, obj1: Type[Model], obj2: Type[Model], **hints: Any) -> Optional[bool]: ...
def allow_relation(self, obj1: type[Model], obj2: type[Model], **hints: Any) -> Optional[bool]: ...

def allow_migrate(
self, db: str, app_label: str, model_name: Optional[str] = None, **hints: Any
Expand Down
9 changes: 5 additions & 4 deletions ext/django_stubs_ext/patch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import builtins
from typing import Any, Generic, Iterable, List, Optional, Tuple, Type, TypeVar
from collections.abc import Iterable
from typing import Any, Generic, Optional, TypeVar

from django import VERSION
from django.contrib.admin import ModelAdmin
Expand All @@ -26,7 +27,7 @@
__all__ = ["monkeypatch"]

_T = TypeVar("_T")
_VersionSpec = Tuple[int, int]
_VersionSpec = tuple[int, int]


class MPGeneric(Generic[_T]):
Expand All @@ -39,7 +40,7 @@ class MPGeneric(Generic[_T]):
possible issues we may run into with this method.
"""

def __init__(self, cls: Type[_T], version: Optional[_VersionSpec] = None) -> None:
def __init__(self, cls: type[_T], version: Optional[_VersionSpec] = None) -> None:
"""Set the data fields, basic constructor."""
self.version = version
self.cls = cls
Expand All @@ -52,7 +53,7 @@ def __repr__(self) -> str:
# certain django classes need to be generic, but lack the __class_getitem__ dunder needed to
# annotate them: https://github.com/typeddjango/django-stubs/issues/507
# this list stores them so `monkeypatch` can fix them when called
_need_generic: List[MPGeneric[Any]] = [
_need_generic: list[MPGeneric[Any]] = [
MPGeneric(ModelAdmin),
MPGeneric(SingleObjectMixin),
MPGeneric(FormMixin),
Expand Down
5 changes: 3 additions & 2 deletions ext/tests/test_monkeypatching.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import builtins
from collections.abc import Iterable
from contextlib import suppress
from typing import Iterable, List, Optional, Protocol
from typing import Optional, Protocol

import pytest
from _pytest.fixtures import FixtureRequest
Expand Down Expand Up @@ -29,7 +30,7 @@ def make_generic_classes(
request: FixtureRequest,
monkeypatch: MonkeyPatch,
) -> _MakeGenericClasses:
_extra_classes: List[type] = []
_extra_classes: list[type] = []

def fin() -> None:
for el in _need_generic:
Expand Down
6 changes: 3 additions & 3 deletions mypy_django_plugin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import textwrap
from functools import partial
from pathlib import Path
from typing import Any, Callable, Dict, NoReturn, Optional
from typing import Any, Callable, NoReturn, Optional

if sys.version_info[:2] >= (3, 11):
import tomllib
Expand Down Expand Up @@ -79,7 +79,7 @@ def parse_toml_file(self, filepath: Path) -> None:
toml_exit(COULD_NOT_LOAD_FILE)

try:
config: Dict[str, Any] = data["tool"]["django-stubs"]
config: dict[str, Any] = data["tool"]["django-stubs"]
except KeyError:
toml_exit(MISSING_SECTION.format(section="tool.django-stubs"))

Expand Down Expand Up @@ -123,7 +123,7 @@ def parse_ini_file(self, filepath: Path) -> None:
except ValueError:
exit_with_error(INVALID_BOOL_SETTING.format(key="strict_settings"))

def to_json(self, extra_data: Dict[str, Any]) -> Dict[str, Any]:
def to_json(self, extra_data: dict[str, Any]) -> dict[str, Any]:
"""We use this method to reset mypy cache via `report_config_data` hook."""
return {
"django_settings_module": self.django_settings_module,
Expand Down
Loading
Loading