Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into formfield
Browse files Browse the repository at this point in the history
  • Loading branch information
intgr committed Oct 18, 2023
2 parents 45ae19a + bcf6356 commit 0c97249
Show file tree
Hide file tree
Showing 127 changed files with 1,506 additions and 626 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
fail-fast: false
steps:
- uses: actions/checkout@v4
Expand All @@ -31,7 +31,7 @@ jobs:
- name: Install dependencies
run: |
pip install -U pip setuptools wheel
pip install -r ./requirements.txt
SETUPTOOLS_ENABLE_FEATURES=legacy-editable pip install -r ./requirements.txt
- name: Run mypy on plugin code
run: mypy --strict mypy_django_plugin
Expand All @@ -48,7 +48,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
shard: [0, 1, 2, 3]
fail-fast: false
steps:
Expand All @@ -64,7 +64,7 @@ jobs:
- name: Install dependencies
run: |
pip install -U pip setuptools wheel
pip install -r ./requirements.txt
SETUPTOOLS_ENABLE_FEATURES=legacy-editable pip install -r ./requirements.txt
# Must match `shard` definition in the test matrix:
- name: Run tests
Expand All @@ -75,7 +75,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11']
python-version: ['3.12']
fail-fast: false
steps:
- uses: actions/checkout@v4
Expand All @@ -90,7 +90,7 @@ jobs:
- name: Install dependencies
run: |
pip install -U pip setuptools wheel
pip install -r ./requirements.txt
SETUPTOOLS_ENABLE_FEATURES=legacy-editable pip install -r ./requirements.txt
- name: Run stubtest
run: bash ./scripts/stubtest.sh
Expand All @@ -101,10 +101,10 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.8', '3.9', '3.10', '3.11']
django-version: ['3.2', '4.2']
include:
- python-version: '3.11'
- python-version: '3.12'
django-version: '4.1'
steps:
- uses: actions/checkout@v4
Expand All @@ -119,7 +119,7 @@ jobs:
- name: Install dependencies
run: |
pip install -U pip setuptools wheel
pip install -r ./requirements.txt
SETUPTOOLS_ENABLE_FEATURES=legacy-editable pip install -r ./requirements.txt
pip install "Django==${{ matrix.django-version }}"
pip check
Expand Down
19 changes: 5 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_language_version:
python: python3.11
python: python3.12
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml
- id: trailing-whitespace
Expand All @@ -13,25 +13,16 @@ repos:
- id: check-merge-conflict
- id: end-of-file-fixer
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.290
rev: v0.0.292
hooks:
- id: ruff
args: ["--fix", "--exit-non-zero-on-fix"]
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 23.10.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
- flake8-no-pep420==2.6.0
- flake8-pyi==23.5.0
types: []
files: ^.*.pyi?$
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.2.6
hooks:
- id: codespell
additional_dependencies:
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ source .venv/bin/activate
Then install the dev requirements:

```bash
pip install -r ./requirements.txt
SETUPTOOLS_ENABLE_FEATURES=legacy-editable pip install -r ./requirements.txt
```

Finally, install the pre-commit hooks:
Expand All @@ -55,7 +55,7 @@ pre-commit install

### Testing and Linting

We use `mypy`, `pytest`, `flake8`, and `black` for quality control. All tools except pytest are executed using pre-commit when you make a commit.
We use `mypy`, `pytest`, `ruff`, and `black` for quality control. `ruff` and `black` are executed using pre-commit when you make a commit.
To ensure there are not formatting or typing issues in the entire repository you can run:

```bash
Expand Down Expand Up @@ -88,7 +88,7 @@ We have two special files to allow errors:
You might also want to disable `incremental` mode while working on `stubtest` changes.
This mode leads to several known problems (stubs do not show up or have strange errors).

**Important**: right now we only run `stubtest` on Python 3.11 (because it is the latest released version at the moment), any other versions might generate different outputs. Any work to create per-version allowlists is welcome.
**Important**: right now we only run `stubtest` on Python 3.12 (because it is the latest released version at the moment), any other versions might generate different outputs. Any work to create per-version allowlists is welcome.

## Submission Guidelines

Expand All @@ -108,7 +108,7 @@ For instance, the statement `class SomeClass(SuperType[int])` implicitly transla
If `SuperType` doesn't define the `__class_getitem__` method, this causes a runtime error, even if the code passes type checking.

When adding a new generic class, or changing an existing class to use generics, run a quick test to see if it causes a runtime error.
If it does, please add the new generic class to the `_need_generic` list in the [`django_stubs_ext.patch` module](https://github.com/typeddjango/django-stubs/blob/master/django_stubs_ext/django_stubs_ext/patch.py).
If it does, please add the new generic class to the `_need_generic` list in the [`django_stubs_ext.patch` module](https://github.com/typeddjango/django-stubs/blob/master/ext/django_stubs_ext/patch.py).

## Private attributes

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ We rely on different `django` and `mypy` versions:

| django-stubs | Mypy version | Django version | Django partial support | Python version |
|----------------|--------------|----------------|------------------------|----------------|
| (next release) | 1.5.x | 4.2 | 4.1, 3.2 | 3.8 - 3.12 |
| 4.2.4 | 1.5.x | 4.2 | 4.1, 3.2 | 3.8 - 3.11 |
| 4.2.3 | 1.4.x | 4.2 | 4.1, 3.2 | 3.8 - 3.11 |
| 4.2.2 | 1.4.x | 4.2 | 4.1, 3.2 | 3.8 - 3.11 |
| 4.2.1 | 1.3.x | 4.2 | 4.1, 3.2 | 3.8 - 3.11 |
Expand Down Expand Up @@ -129,7 +131,7 @@ when you will try to use `QuerySet[MyModel]`, `Manager[MyModel]` or some other D

This happens because these Django classes do not support [`__class_getitem__`](https://www.python.org/dev/peps/pep-0560/#class-getitem) magic method in runtime.

1. You can go with our [`django_stubs_ext`](https://github.com/typeddjango/django-stubs/tree/master/django_stubs_ext) helper, that patches all the types we use as Generic in django.
1. You can go with our [`django_stubs_ext`](https://github.com/typeddjango/django-stubs/tree/master/ext) helper, that patches all the types we use as Generic in django.

Install it:

Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/admin/checks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
def check(self, admin_obj: BaseModelAdmin, **kwargs: Any) -> list[CheckMessage]: ...

class InlineModelAdminChecks(BaseModelAdminChecks):
def check(self, inline_obj: BaseModelAdmin, **kwargs: Any) -> list[CheckMessage]: ... # type: ignore
def check(self, inline_obj: BaseModelAdmin, **kwargs: Any) -> list[CheckMessage]: ... # type: ignore[override]

def must_be(type: Any, option: Any, obj: Any, id: Any) -> list[CheckMessage]: ...
def must_inherit_from(parent: Any, option: Any, obj: Any, id: Any) -> list[CheckMessage]: ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/admin/decorators.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Callable, Sequence
from typing import Any, TypeVar, overload # noqa: Y037
from typing import Any, TypeVar, overload

from django.contrib.admin import ModelAdmin
from django.contrib.admin.sites import AdminSite
Expand All @@ -15,7 +15,7 @@ _ModelAdmin = TypeVar("_ModelAdmin", bound=ModelAdmin)
_Request = TypeVar("_Request", bound=HttpRequest)
_QuerySet = TypeVar("_QuerySet", bound=QuerySet)
# This is deliberately different from _DisplayT defined in contrib.admin.options
_DisplayCallable: TypeAlias = Callable[[_ModelAdmin, _Model], Any] | Callable[[_Model], Any] # noqa: Y037
_DisplayCallable: TypeAlias = Callable[[_ModelAdmin, _Model], Any] | Callable[[_Model], Any]
_DisplayCallableT = TypeVar("_DisplayCallableT", bound=_DisplayCallable)
_ActionReturn = TypeVar("_ActionReturn", bound=HttpResponseBase | None)

Expand Down
13 changes: 6 additions & 7 deletions django-stubs/contrib/admin/options.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
from typing import Any, Generic, Literal, Optional, TypeVar # noqa: Y037 # https://github.com/python/mypy/issues/12211
from typing import Any, Generic, Literal, TypeVar

from django import forms
from django.contrib.admin.filters import FieldListFilter, ListFilter
Expand Down Expand Up @@ -63,7 +63,6 @@ class _FieldOpts(_OptionalFieldOpts, total=True):
# https://github.com/python/mypy/issues/8921
# _FieldsetSpec = Sequence[Tuple[Optional[str], _FieldOpts]]
_FieldsetSpec: TypeAlias = _ListOrTuple[tuple[_StrOrPromise | None, _FieldOpts]]
# https://github.com/python/mypy/issues/12211
_ListFilterT: TypeAlias = (
type[ListFilter]
| Field
Expand All @@ -81,7 +80,7 @@ class BaseModelAdmin(Generic[_ModelT]):
raw_id_fields: Sequence[str]
fields: _FieldGroups | None
exclude: Sequence[str] | None
fieldsets: Optional[_FieldsetSpec] # noqa: UP007
fieldsets: _FieldsetSpec | None
form: type[forms.ModelForm[_ModelT]]
filter_vertical: Sequence[str]
filter_horizontal: Sequence[str]
Expand Down Expand Up @@ -307,10 +306,10 @@ class InlineModelAdmin(Generic[_ChildModelT, _ParentModelT], BaseModelAdmin[_Chi
self, request: HttpRequest, obj: _ParentModelT | None = ..., **kwargs: Any
) -> type[BaseInlineFormSet[_ChildModelT, _ParentModelT, forms.ModelForm[_ChildModelT]]]: ...
def get_queryset(self, request: HttpRequest) -> QuerySet[_ChildModelT]: ...
def has_add_permission(self, request: HttpRequest, obj: _ParentModelT | None) -> bool: ... # type: ignore
def has_change_permission(self, request: HttpRequest, obj: _ParentModelT | None = ...) -> bool: ... # type: ignore
def has_delete_permission(self, request: HttpRequest, obj: _ParentModelT | None = ...) -> bool: ... # type: ignore
def has_view_permission(self, request: HttpRequest, obj: _ParentModelT | None = ...) -> bool: ... # type: ignore
def has_add_permission(self, request: HttpRequest, obj: _ParentModelT | None) -> bool: ... # type: ignore[override]
def has_change_permission(self, request: HttpRequest, obj: _ParentModelT | None = ...) -> bool: ... # type: ignore[override]
def has_delete_permission(self, request: HttpRequest, obj: _ParentModelT | None = ...) -> bool: ... # type: ignore[override]
def has_view_permission(self, request: HttpRequest, obj: _ParentModelT | None = ...) -> bool: ... # type: ignore[override]

class StackedInline(InlineModelAdmin[_ChildModelT, _ParentModelT]):
template: str
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/admin/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def lookup_field(
name: Callable | str, obj: Model, model_admin: BaseModelAdmin | None = ...
) -> tuple[Field | None, str | None, Any]: ...
@overload
def label_for_field( # type: ignore
def label_for_field( # type: ignore[misc]
name: Callable | str,
model: type[Model],
model_admin: BaseModelAdmin | None = ...,
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/admin/widgets.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ForeignKeyRawIdWidget(forms.TextInput):
def label_and_url_for_value(self, value: Any) -> tuple[str, str]: ...

class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
rel: ManyToManyRel # type: ignore
rel: ManyToManyRel # type: ignore[assignment]
def __init__(
self,
rel: ManyToManyRel,
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/auth/base_user.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Literal, TypeVar, overload
from typing import Any, ClassVar, Literal, TypeVar, overload

from django.db import models
from django.db.models.base import Model
Expand All @@ -14,7 +14,7 @@ class BaseUserManager(models.Manager[_T]):
def get_by_natural_key(self, username: str | None) -> _T: ...

class AbstractBaseUser(models.Model):
REQUIRED_FIELDS: list[str]
REQUIRED_FIELDS: ClassVar[list[str]]

password = models.CharField(max_length=128)
last_login = models.DateTimeField(blank=True, null=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import getpass as getpass # noqa: F401
import getpass as getpass
from typing import Any

from django.core.management.base import BaseCommand
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/gis/db/backends/mysql/features.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ class DatabaseFeatures(BaseSpatialFeatures, MySQLDatabaseFeatures):
@property
def empty_intersection_returns_none(self) -> bool: ...
@property
def supports_geometry_field_unique_index(self) -> bool: ... # type: ignore
def supports_geometry_field_unique_index(self) -> bool: ... # type: ignore[override]
@property
def django_test_skips(self) -> dict[str, Any]: ... # type: ignore
def django_test_skips(self) -> dict[str, Any]: ... # type: ignore[override]
8 changes: 4 additions & 4 deletions django-stubs/contrib/gis/db/backends/mysql/operations.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations):
@property
def mariadb(self) -> bool: ...
@property
def mysql(self) -> bool: ... # type: ignore
def mysql(self) -> bool: ... # type: ignore[override]
@property
def select(self) -> str: ... # type: ignore
def select(self) -> str: ... # type: ignore[override]
@property
def from_text(self) -> str: ... # type: ignore
def from_text(self) -> str: ... # type: ignore[override]
@property
def gis_operators(self) -> dict[str, SpatialOperator]: ...
disallowed_aggregates: Any
@property
def unsupported_functions(self) -> set[str]: ... # type: ignore
def unsupported_functions(self) -> set[str]: ... # type: ignore[override]
def geo_db_type(self, f: Any) -> Any: ...
def get_distance(self, f: Any, value: Any, lookup_type: Any) -> list[Any]: ...
def get_geometry_converter(self, expression: Any) -> Callable[[Any, Any, Any], GEOSGeometryBase | None]: ...
1 change: 0 additions & 1 deletion django-stubs/contrib/gis/db/models/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# noqa: F401
from django.contrib.gis.db.models.aggregates import *
from django.contrib.gis.db.models.fields import GeometryCollectionField as GeometryCollectionField
from django.contrib.gis.db.models.fields import GeometryField as GeometryField
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/gis/geos/io.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib.gis.geos.geometry import GEOSGeometry
from django.contrib.gis.geos.prototypes.io import WKBWriter as WKBWriter # noqa: F401
from django.contrib.gis.geos.prototypes.io import WKBWriter as WKBWriter
from django.contrib.gis.geos.prototypes.io import WKTWriter as WKTWriter
from django.contrib.gis.geos.prototypes.io import _WKBReader, _WKTReader

Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/postgres/fields/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ class ArrayField(CheckFieldDefaultMixin, Field[_ST, _GT]):
error_messages: _ErrorMessagesMapping | None = ...,
) -> None: ...
@property
def description(self) -> str: ... # type: ignore
def description(self) -> str: ... # type: ignore[override]
def get_transform(self, name: Any) -> type[Transform] | None: ...
4 changes: 2 additions & 2 deletions django-stubs/contrib/postgres/forms/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SimpleArrayField(forms.CharField):
) -> None: ...
def clean(self, value: Any) -> Sequence[Any]: ...
def prepare_value(self, value: Any) -> Any: ...
def to_python(self, value: Any) -> Sequence[Any]: ... # type: ignore
def to_python(self, value: Any) -> Sequence[Any]: ... # type: ignore[override]
def validate(self, value: Sequence[Any]) -> None: ...
def run_validators(self, value: Sequence[Any]) -> None: ...
def has_changed(self, initial: Any, data: Any) -> bool: ...
Expand All @@ -43,7 +43,7 @@ class SplitArrayWidget(forms.Widget):
def id_for_label(self, id_: str) -> str: ...
def get_context(self, name: str, value: Any, attrs: _OptAttrs | None = ...) -> dict[str, Any]: ...
@property
def needs_multipart_form(self) -> bool: ... # type: ignore
def needs_multipart_form(self) -> bool: ... # type: ignore[override]

class SplitArrayField(forms.Field):
default_error_messages: _ErrorMessagesDict
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/postgres/forms/hstore.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ class HStoreField(forms.CharField):
widget: _ClassLevelWidgetT
default_error_messages: _ErrorMessagesDict
def prepare_value(self, value: Any) -> Any: ...
def to_python(self, value: Any) -> dict[str, str | None]: ... # type: ignore
def to_python(self, value: Any) -> dict[str, str | None]: ... # type: ignore[override]
def has_changed(self, initial: Any, data: Any) -> bool: ...
2 changes: 1 addition & 1 deletion django-stubs/contrib/postgres/indexes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ from django.utils.datastructures import _ListOrTuple

class PostgresIndex(Index):
@property
def max_name_length(self) -> int: ... # type: ignore
def max_name_length(self) -> int: ... # type: ignore[override]
def create_sql(
self, model: type[Model], schema_editor: BaseDatabaseSchemaEditor, using: str = ..., **kwargs: Any
) -> Statement: ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/postgres/search.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SearchQueryCombinable:
def __and__(self, other: SearchQueryCombinable) -> Self: ...
def __rand__(self, other: SearchQueryCombinable) -> Self: ...

class SearchQuery(SearchQueryCombinable, Func): # type: ignore
class SearchQuery(SearchQueryCombinable, Func): # type: ignore[misc]
SEARCH_TYPES: dict[str, str]
def __init__(
self,
Expand All @@ -60,7 +60,7 @@ class SearchQuery(SearchQueryCombinable, Func): # type: ignore
) -> None: ...
def __invert__(self) -> Self: ... # type: ignore[override]

class CombinedSearchQuery(SearchQueryCombinable, CombinedExpression): # type: ignore
class CombinedSearchQuery(SearchQueryCombinable, CombinedExpression): # type: ignore[misc]
def __init__(
self,
lhs: Combinable,
Expand Down
3 changes: 2 additions & 1 deletion django-stubs/contrib/sessions/exceptions.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.core.exceptions import SuspiciousOperation
from django.core.exceptions import BadRequest, SuspiciousOperation

class InvalidSessionKey(SuspiciousOperation): ...
class SuspiciousSession(SuspiciousOperation): ...
class SessionInterrupted(BadRequest): ...
Loading

0 comments on commit 0c97249

Please sign in to comment.