Skip to content

Commit

Permalink
Merge branch 'master' into log-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
JaeHyuckSa authored Dec 6, 2024
2 parents 3ca4a90 + 9351ae1 commit 76d5864
Show file tree
Hide file tree
Showing 58 changed files with 310 additions and 248 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Build ext package
run: python -m build ext/
- name: Publish ext to PyPI
uses: pypa/gh-action-pypi-publish@v1.10.3
uses: pypa/gh-action-pypi-publish@v1.12.2
with:
packages-dir: ext/dist/

Expand All @@ -53,4 +53,4 @@ jobs:
- name: Build package
run: python -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@v1.10.3
uses: pypa/gh-action-pypi-publish@v1.12.2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.egg-info
.DS_Store
.idea/
.vscode/
.mypy_cache/
.pytest_cache/
.ruff_cache/
Expand Down
7 changes: 2 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ repos:
args: [--fix=lf]
- id: check-case-conflict
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.0
rev: v0.8.1
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ We rely on different `django` and `mypy` versions:

| django-stubs | Mypy version | Django version | Django partial support | Python version |
|----------------|--------------|----------------|------------------------|----------------|
| 5.1.1 | 1.13.x | 5.1 | 4.2 | 3.8 - 3.12 |
| 5.1.0 | 1.11.x | 5.1 | 4.2 | 3.8 - 3.12 |
| 5.0.4 | 1.11.x | 5.0 | 4.2 | 3.8 - 3.12 |
| 5.0.3 | 1.11.x | 5.0 | 4.2 | 3.8 - 3.12 |
Expand All @@ -67,6 +68,9 @@ We rely on different `django` and `mypy` versions:
| 1.15.0 | 1.0.x | 4.1 | 4.0, 3.2 | 3.7 - 3.11 |
| 1.14.0 | 0.990+ | 4.1 | 4.0, 3.2 | 3.7 - 3.11 |

What "partial" support means, and why we don't pin to the exact Django/mypy version, is explained in
https://github.com/typeddjango/django-stubs/discussions/2101#discussioncomment-9276632.

## Features

### Type checking of Model Meta attributes
Expand Down
11 changes: 5 additions & 6 deletions django-stubs/contrib/admin/options.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import enum
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
from typing import Any, Generic, Literal, TypeVar, type_check_only
from typing import Any, Generic, Literal, TypeVar, cast, type_check_only

from django import forms
from django.contrib.admin.filters import FieldListFilter, ListFilter
from django.contrib.admin.models import LogEntry
from django.contrib.admin.sites import AdminSite
from django.contrib.admin.views.main import ChangeList
from django.contrib.auth.forms import AdminPasswordChangeForm
from django.contrib.contenttypes.models import ContentType
from django.core.checks.messages import CheckMessage
from django.core.paginator import Paginator
Expand Down Expand Up @@ -45,9 +44,9 @@ VERTICAL: Literal[2]
_Direction: TypeAlias = Literal[1, 2]

class ShowFacets(enum.Enum):
NEVER: str
ALLOW: str
ALWAYS: str
NEVER = cast(str, ...)
ALLOW = cast(str, ...)
ALWAYS = cast(str, ...)

def get_content_type_for_model(obj: type[Model] | Model) -> ContentType: ...
def get_ul_class(radio_style: int) -> str: ...
Expand Down Expand Up @@ -225,7 +224,7 @@ class ModelAdmin(BaseModelAdmin[_ModelT]):
def _get_edited_object_pks(self, request: HttpRequest, prefix: str) -> list[str]: ...
def _get_list_editable_queryset(self, request: HttpRequest, prefix: str) -> QuerySet[_ModelT]: ...
def construct_change_message(
self, request: HttpRequest, form: AdminPasswordChangeForm, formsets: Iterable[BaseFormSet], add: bool = ...
self, request: HttpRequest, form: forms.Form, formsets: Iterable[BaseFormSet], add: bool = ...
) -> list[dict[str, dict[str, list[str]]]]: ...
def message_user(
self,
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
5 changes: 2 additions & 3 deletions django-stubs/contrib/admin/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ from uuid import UUID
from _typeshed import Unused
from django.contrib.admin.options import BaseModelAdmin
from django.contrib.admin.sites import AdminSite
from django.contrib.auth.forms import AdminPasswordChangeForm
from django.db.models.base import Model
from django.db.models.deletion import Collector
from django.db.models.fields import Field, reverse_related
from django.db.models.options import Options
from django.db.models.query import QuerySet
from django.db.models.query_utils import Q
from django.forms.forms import BaseForm
from django.forms.forms import BaseForm, Form
from django.forms.formsets import BaseFormSet
from django.http.request import HttpRequest
from django.utils.datastructures import _IndexableCollection
Expand Down Expand Up @@ -100,5 +99,5 @@ def get_model_from_relation(field: Field | reverse_related.ForeignObjectRel) ->
def reverse_field_path(model: type[Model], path: str) -> tuple[type[Model], str]: ...
def get_fields_from_path(model: type[Model], path: str) -> list[Field]: ...
def construct_change_message(
form: AdminPasswordChangeForm, formsets: Iterable[BaseFormSet], add: bool
form: Form, formsets: Iterable[BaseFormSet], add: bool
) -> list[dict[str, dict[str, list[str]]]]: ...
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
6 changes: 3 additions & 3 deletions django-stubs/contrib/gis/gdal/srs.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from enum import IntEnum
from typing import Any, AnyStr
from typing import Any, AnyStr, cast

from django.contrib.gis.gdal.base import GDALBase
from typing_extensions import Self

class AxisOrder(IntEnum):
TRADITIONAL: int
AUTHORITY: int
TRADITIONAL = cast(int, ...)
AUTHORITY = cast(int, ...)

class SpatialReference(GDALBase):
destructor: Any
Expand Down
5 changes: 5 additions & 0 deletions django-stubs/contrib/gis/geoip2/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ from pathlib import Path
from typing import Any

from django.contrib.gis.geos import Point
from django.utils.functional import cached_property

GEOIP_SETTINGS: dict[str, Any]

Expand All @@ -23,6 +24,10 @@ class GeoIP2:
def country_code(self, query: str) -> str: ...
def country_name(self, query: str) -> str: ...
def country(self, query: str) -> dict[str, Any]: ...
@cached_property
def is_city(self) -> bool: ...
@cached_property
def is_country(self) -> bool: ...
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]: ...
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/contrib/postgres/fields/array.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Iterable, Sequence
from typing import Any, TypeVar
from typing import Any, ClassVar, TypeVar

from _typeshed import Unused
from django.core.validators import _ValidatorCallable
Expand All @@ -22,7 +22,7 @@ class ArrayField(CheckFieldDefaultMixin, Field[_ST, _GT]):
_pyi_private_get_type: list[Any]

empty_strings_allowed: bool
default_error_messages: _ErrorMessagesDict
default_error_messages: ClassVar[_ErrorMessagesDict]
base_field: Field
size: int | None
default_validators: Sequence[_ValidatorCallable]
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/contrib/postgres/forms/array.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Sequence
from typing import Any
from typing import Any, ClassVar

from django import forms
from django.db.models.fields import _ErrorMessagesDict
Expand All @@ -10,7 +10,7 @@ from django.forms.widgets import _OptAttrs
from ..utils import prefix_validation_error as prefix_validation_error

class SimpleArrayField(forms.CharField):
default_error_messages: _ErrorMessagesDict
default_error_messages: ClassVar[_ErrorMessagesDict]
base_field: forms.Field
delimiter: str
min_length: int | None
Expand Down Expand Up @@ -46,7 +46,7 @@ class SplitArrayWidget(forms.Widget):
def needs_multipart_form(self) -> bool: ... # type: ignore[override]

class SplitArrayField(forms.Field):
default_error_messages: _ErrorMessagesDict
default_error_messages: ClassVar[_ErrorMessagesDict]
base_field: forms.Field
size: int
remove_trailing_nulls: bool
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/postgres/forms/hstore.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Any
from typing import Any, ClassVar

from django import forms
from django.db.models.fields import _ErrorMessagesDict
from django.forms.fields import _ClassLevelWidgetT

class HStoreField(forms.CharField):
widget: _ClassLevelWidgetT
default_error_messages: _ErrorMessagesDict
default_error_messages: ClassVar[_ErrorMessagesDict]
def prepare_value(self, value: Any) -> Any: ...
def to_python(self, value: Any) -> dict[str, str | None]: ... # type: ignore[override]
def has_changed(self, initial: Any, data: Any) -> bool: ...
12 changes: 6 additions & 6 deletions django-stubs/contrib/postgres/forms/ranges.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, ClassVar

from django import forms
from django.db.models.fields import _ErrorMessagesDict
Expand All @@ -13,7 +13,7 @@ class HiddenRangeWidget(RangeWidget):
def __init__(self, attrs: _OptAttrs | None = None) -> None: ...

class BaseRangeField(forms.MultiValueField):
default_error_messages: _ErrorMessagesDict
default_error_messages: ClassVar[_ErrorMessagesDict]
base_field: type[forms.Field]
range_type: type[Range]
hidden_widget: type[forms.Widget]
Expand All @@ -22,21 +22,21 @@ class BaseRangeField(forms.MultiValueField):
def compress(self, values: tuple[Any | None, Any | None]) -> Range | None: ...

class IntegerRangeField(BaseRangeField):
default_error_messages: _ErrorMessagesDict
default_error_messages: ClassVar[_ErrorMessagesDict]
base_field: type[forms.Field]
range_type: type[Range]

class DecimalRangeField(BaseRangeField):
default_error_messages: _ErrorMessagesDict
default_error_messages: ClassVar[_ErrorMessagesDict]
base_field: type[forms.Field]
range_type: type[Range]

class DateTimeRangeField(BaseRangeField):
default_error_messages: _ErrorMessagesDict
default_error_messages: ClassVar[_ErrorMessagesDict]
base_field: type[forms.Field]
range_type: type[Range]

class DateRangeField(BaseRangeField):
default_error_messages: _ErrorMessagesDict
default_error_messages: ClassVar[_ErrorMessagesDict]
base_field: type[forms.Field]
range_type: type[Range]
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
5 changes: 3 additions & 2 deletions django-stubs/db/models/constants.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from enum import Enum
from typing import cast

LOOKUP_SEP: str

class OnConflict(Enum):
IGNORE: str
UPDATE: str
IGNORE = cast(str, ...)
UPDATE = cast(str, ...)
6 changes: 3 additions & 3 deletions django-stubs/db/models/constraints.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Sequence
from enum import Enum
from typing import Any, overload
from typing import Any, cast, overload

from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.models.base import Model
Expand All @@ -10,8 +10,8 @@ from django.utils.functional import _StrOrPromise
from typing_extensions import Self, deprecated

class Deferrable(Enum):
DEFERRED: str
IMMEDIATE: str
DEFERRED = cast(str, ...)
IMMEDIATE = cast(str, ...)

class BaseConstraint:
name: str
Expand Down
7 changes: 4 additions & 3 deletions django-stubs/db/models/fields/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ BLANK_CHOICE_DASH: list[tuple[str, str]]

_ChoicesList: TypeAlias = Sequence[_Choice] | Sequence[_ChoiceNamedGroup]
_LimitChoicesTo: TypeAlias = Q | dict[str, Any]
_LimitChoicesToCallable: TypeAlias = Callable[[], _LimitChoicesTo]

_F = TypeVar("_F", bound=Field, covariant=True)

Expand All @@ -39,7 +40,7 @@ class _FieldDescriptor(Protocol[_F]):
@property
def field(self) -> _F: ...

_AllLimitChoicesTo: TypeAlias = _LimitChoicesTo | _ChoicesCallable # noqa: PYI047
_AllLimitChoicesTo: TypeAlias = _LimitChoicesTo | _LimitChoicesToCallable | _ChoicesCallable # noqa: PYI047
_ErrorMessagesMapping: TypeAlias = Mapping[str, _StrOrPromise]
_ErrorMessagesDict: TypeAlias = dict[str, _StrOrPromise]

Expand Down Expand Up @@ -146,7 +147,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
creation_counter: int
auto_creation_counter: int
default_validators: Sequence[validators._ValidatorCallable]
default_error_messages: _ErrorMessagesDict
default_error_messages: ClassVar[_ErrorMessagesDict]
hidden: bool
system_check_removed_details: Any | None
system_check_deprecated_details: Any | None
Expand Down Expand Up @@ -442,7 +443,7 @@ class GenericIPAddressField(Field[_ST, _GT]):
_pyi_private_set_type: str | int | Callable[..., Any] | Combinable
_pyi_private_get_type: str

default_error_messages: _ErrorMessagesDict
default_error_messages: ClassVar[_ErrorMessagesDict]
unpack_ipv4: bool
protocol: str
def __init__(
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
Loading

0 comments on commit 76d5864

Please sign in to comment.