Skip to content

Commit 7bf13d6

Browse files
authored
Merge branch 'master' into ValidationError-params
2 parents 9069938 + 92c8c45 commit 7bf13d6

20 files changed

+115
-108
lines changed

.github/workflows/pre-commit-autoupdate.yml

Lines changed: 0 additions & 45 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@ on:
88
workflow_dispatch:
99

1010
jobs:
11+
mypy-self-check:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Install dependencies
23+
run: |
24+
pip install -U pip setuptools wheel
25+
pip install -r ./requirements.txt
26+
- name: Run mypy on plugin code
27+
run: mypy --strict mypy_drf_plugin
28+
- name: Run mypy on scripts and utils
29+
run: mypy --strict scripts
30+
- name: Run mypy on stubs
31+
run: mypy --cache-dir=/dev/null --no-incremental rest_framework-stubs
32+
1133
lint:
1234
runs-on: ubuntu-latest
1335
strategy:
@@ -31,7 +53,7 @@ jobs:
3153
runs-on: ubuntu-latest
3254
strategy:
3355
matrix:
34-
python-version: ['3.7', '3.8', '3.9', '3.10']
56+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
3557
steps:
3658
- uses: actions/checkout@v3
3759
- name: Setup system dependencies
@@ -54,7 +76,7 @@ jobs:
5476
runs-on: ubuntu-latest
5577
strategy:
5678
matrix:
57-
python-version: ['3.7', '3.8', '3.9', '3.10']
79+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
5880
steps:
5981
- uses: actions/checkout@v3
6082
- name: Setup system dependencies

.pre-commit-config.yaml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ repos:
1515
hooks:
1616
- id: pyupgrade
1717
args: ["--py36-plus"]
18-
- repo: https://github.com/pre-commit/mirrors-isort
19-
rev: v5.10.1
18+
- repo: https://github.com/pycqa/isort
19+
rev: 5.12.0
2020
hooks:
2121
- id: isort
22+
name: isort (python)
23+
- id: isort
24+
name: isort (pyi)
25+
types: [pyi]
2226
- repo: https://github.com/psf/black
2327
rev: 23.1.0
2428
hooks:
@@ -31,12 +35,10 @@ repos:
3135
- flake8-pyi==22.11.0
3236
types: []
3337
files: ^.*.pyi?$
34-
- repo: local
35-
hooks:
36-
- id: mypy
37-
name: mypy
38-
entry: mypy
39-
language: system
40-
types: [ python ]
41-
exclude: "scripts/*"
42-
args: [ "--cache-dir=/dev/null", "--no-incremental" ]
38+
39+
ci:
40+
autofix_commit_msg: '[pre-commit.ci] auto fixes from pre-commit.com hooks'
41+
autofix_prs: true
42+
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
43+
autoupdate_schedule: weekly
44+
submodules: false

mypy_drf_plugin/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Callable, Dict, Optional
1+
from typing import Callable, Dict, Optional, Type
22

33
from mypy.nodes import TypeInfo
44
from mypy.options import Options
@@ -28,9 +28,10 @@ def __init__(self, options: Options) -> None:
2828
def _get_currently_defined_serializers(self) -> Dict[str, int]:
2929
base_serializer_sym = self.lookup_fully_qualified(fullnames.BASE_SERIALIZER_FULLNAME)
3030
if base_serializer_sym is not None and isinstance(base_serializer_sym.node, TypeInfo):
31-
return base_serializer_sym.node.metadata.setdefault("drf", {}).setdefault(
31+
serializer_bases: Dict[str, int] = base_serializer_sym.node.metadata.setdefault("drf", {}).setdefault(
3232
"serializer_bases", {fullnames.BASE_SERIALIZER_FULLNAME: 1}
3333
)
34+
return serializer_bases
3435
else:
3536
return {}
3637

@@ -40,5 +41,5 @@ def get_base_class_hook(self, fullname: str) -> Optional[Callable[[ClassDefConte
4041
return None
4142

4243

43-
def plugin(version):
44+
def plugin(version: str) -> Type[NewSemanalDRFPlugin]:
4445
return NewSemanalDRFPlugin

requirements.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
wheel
2-
gitpython==3.1.30
2+
gitpython==3.1.31
33
pre-commit==2.21.0
44
pytest==7.2.1
55
pytest-mypy-plugins==1.10.1
66
djangorestframework==3.14.0
7-
types-pytz==2022.7.1.0
8-
types-requests==2.28.11.8
9-
types-urllib3==1.26.25.4
10-
django-stubs==1.13.0
7+
types-pytz==2022.7.1.2
8+
types-requests==2.28.11.14
9+
types-urllib3==1.26.25.7
10+
django-stubs==1.15.0
1111
django-stubs-ext==0.7.0
1212
-e .[compatible-mypy,coreapi,markdown]

rest_framework-stubs/generics.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ from typing import Any, Protocol, TypeVar
33

44
from django.db.models import Manager, Model
55
from django.db.models.query import QuerySet
6-
76
from rest_framework import mixins, views
87
from rest_framework.filters import BaseFilterBackend
98
from rest_framework.pagination import BasePagination

rest_framework-stubs/mixins.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from typing import Any, TypeVar
22

33
from django.db.models import Model
4-
54
from rest_framework.generics import UsesQuerySet
65
from rest_framework.request import Request
76
from rest_framework.response import Response

rest_framework-stubs/permissions.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from collections.abc import Sequence
22
from typing import Any, Protocol, Union # noqa: Y037 # https://github.com/python/mypy/issues/12392
3-
from typing_extensions import TypeAlias
43

54
from django.db.models import Model, QuerySet
65
from rest_framework.request import Request
76
from rest_framework.views import APIView
7+
from typing_extensions import TypeAlias
88

99
SAFE_METHODS: Sequence[str]
1010

rest_framework-stubs/relations.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from collections import OrderedDict
22
from collections.abc import Callable, Iterable, Mapping, Sequence
33
from typing import Any, Generic, TypeVar
4-
from _typeshed import Self
54

5+
from _typeshed import Self
66
from django.db.models import Manager, Model, QuerySet
77
from rest_framework.fields import Field, Option
88
from rest_framework.request import Request

rest_framework-stubs/renderers.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from json import JSONEncoder
21
from collections.abc import Iterable, Mapping, Sequence
2+
from json import JSONEncoder
33
from typing import Any
44

55
from django import forms

rest_framework-stubs/request.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
from contextlib import contextmanager
2-
from types import TracebackType
31
from collections.abc import Iterator, Sequence
4-
from contextlib import AbstractContextManager
2+
from contextlib import AbstractContextManager, contextmanager
3+
from types import TracebackType
54
from typing import Any
65

76
from django.contrib.auth.base_user import AbstractBaseUser

rest_framework-stubs/response.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ from collections.abc import Mapping
22
from typing import Any
33

44
from django.template.base import Template
5-
from django.test.utils import ContextList
65
from django.template.response import SimpleTemplateResponse
6+
from django.test.utils import ContextList
77
from django.urls import ResolverMatch
8-
98
from rest_framework.request import Request
109
from rest_framework.test import APIClient
1110

rest_framework-stubs/schemas/generators.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from types import ModuleType
21
from collections.abc import Iterable, Sequence
2+
from types import ModuleType
33
from typing import Any
4-
from typing_extensions import TypeAlias
54

65
from django.db.models.base import Model
76
from rest_framework.compat import coreapi
87
from rest_framework.request import Request
98
from rest_framework.urlpatterns import _AnyURL
109
from rest_framework.views import APIView
10+
from typing_extensions import TypeAlias
1111

1212
def common_path(paths: Iterable[str]) -> str: ...
1313
def get_pk_name(model: type[Model]) -> str: ...

rest_framework-stubs/test.pyi

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections.abc import Iterable, Mapping
12
from typing import Any
23

34
import coreapi
@@ -13,6 +14,13 @@ from django.test.client import RequestFactory as DjangoRequestFactory
1314
from rest_framework.authtoken.models import Token
1415
from rest_framework.request import Request
1516
from rest_framework.response import _MonkeyPatchedResponse
17+
from typing_extensions import TypeAlias
18+
19+
_GetDataType: TypeAlias = (
20+
Mapping[str, str | bytes | int | Iterable[str | bytes | int]]
21+
| Iterable[tuple[str, str | bytes | int | Iterable[str | bytes | int]]]
22+
| None
23+
)
1624

1725
def force_authenticate(
1826
request: HttpRequest, user: AnonymousUser | AbstractBaseUser | None = ..., token: Token | None = ...
@@ -50,7 +58,7 @@ class APIRequestFactory(DjangoRequestFactory):
5058
renderer_classes: Any
5159
def __init__(self, enforce_csrf_checks: bool = ..., **defaults: Any) -> None: ...
5260
def request(self, **kwargs: Any) -> Request: ... # type: ignore[override]
53-
def get(self, path: str, data: dict[str, Any] | str | None = ..., follow: bool = ..., **extra: Any) -> Request: ... # type: ignore[override]
61+
def get(self, path: str, data: _GetDataType = ..., follow: bool = ..., **extra: Any) -> Request: ... # type: ignore[override]
5462
def post(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> Request: ... # type: ignore[override]
5563
def put(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> Request: ... # type: ignore[override]
5664
def patch(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> Request: ... # type: ignore[override]
@@ -68,7 +76,7 @@ class APIClient(APIRequestFactory, DjangoClient):
6876
def credentials(self, **kwargs: Any): ...
6977
def force_authenticate(self, user: AnonymousUser | AbstractBaseUser = ..., token: Token | None = ...) -> None: ...
7078
def request(self, **kwargs: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
71-
def get(self, path: str, data: dict[str, Any] | str | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
79+
def get(self, path: str, data: _GetDataType = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
7280
def post(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
7381
def put(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
7482
def patch(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]

rest_framework-stubs/urlpatterns.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections.abc import Iterable, Sequence
2-
from typing_extensions import TypeAlias
32

43
from django.urls.resolvers import URLPattern, URLResolver
4+
from typing_extensions import TypeAlias
55

66
_AnyURL: TypeAlias = URLPattern | URLResolver
77

rest_framework-stubs/validators.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from collections.abc import Callable, Container, Iterable, MutableMapping
2-
from typing import Any, TypeVar, Protocol
3-
from typing_extensions import TypeAlias
2+
from typing import Any, Protocol, TypeVar
43

54
from django.db.models import Model, QuerySet
65
from rest_framework.fields import Field
76
from rest_framework.serializers import BaseSerializer
7+
from typing_extensions import TypeAlias
88

99
_T = TypeVar("_T", bound=Model)
1010
_V = TypeVar("_V", contravariant=True)

rest_framework-stubs/viewsets.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from collections import OrderedDict
22
from collections.abc import Callable
33
from typing import Any
4-
from typing_extensions import TypeAlias
54

65
from django.http.request import HttpRequest
76
from django.http.response import HttpResponseBase
@@ -10,6 +9,7 @@ from rest_framework.decorators import ViewSetAction
109
from rest_framework.generics import _MT_co
1110
from rest_framework.request import Request
1211
from rest_framework.views import AsView, GenericView
12+
from typing_extensions import TypeAlias
1313

1414
def _is_extra_action(attr: Any) -> bool: ...
1515

scripts/git_helpers.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from typing import Optional
1+
from typing import Optional, Union
22

3-
from git import RemoteProgress, Repo
3+
from git.remote import RemoteProgress
4+
from git.repo import Repo
45

56
from scripts.paths import DRF_SOURCE_DIRECTORY
67

@@ -9,7 +10,9 @@ class ProgressPrinter(RemoteProgress):
910
def line_dropped(self, line: str) -> None:
1011
print(line)
1112

12-
def update(self, op_code, cur_count, max_count=None, message=""):
13+
def update(
14+
self, op_code: int, cur_count: Union[str, float], max_count: Union[str, float, None] = None, message: str = ""
15+
) -> None:
1316
print(self._cur_line)
1417

1518

@@ -19,7 +22,7 @@ def git_checkout_drf(commit_ref: Optional[str] = None) -> None:
1922
repository = Repo.clone_from(
2023
"https://github.com/encode/django-rest-framework.git",
2124
DRF_SOURCE_DIRECTORY,
22-
progress=ProgressPrinter(),
25+
progress=ProgressPrinter(), # type: ignore
2326
branch="master",
2427
depth=100,
2528
)

0 commit comments

Comments
 (0)