Skip to content

Commit

Permalink
Merge branch 'master' into ValidationError-params
Browse files Browse the repository at this point in the history
  • Loading branch information
intgr authored Feb 22, 2023
2 parents 9069938 + 92c8c45 commit 7bf13d6
Show file tree
Hide file tree
Showing 20 changed files with 115 additions and 108 deletions.
45 changes: 0 additions & 45 deletions .github/workflows/pre-commit-autoupdate.yml

This file was deleted.

26 changes: 24 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@ on:
workflow_dispatch:

jobs:
mypy-self-check:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -U pip setuptools wheel
pip install -r ./requirements.txt
- name: Run mypy on plugin code
run: mypy --strict mypy_drf_plugin
- name: Run mypy on scripts and utils
run: mypy --strict scripts
- name: Run mypy on stubs
run: mypy --cache-dir=/dev/null --no-incremental rest_framework-stubs

lint:
runs-on: ubuntu-latest
strategy:
Expand All @@ -31,7 +53,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v3
- name: Setup system dependencies
Expand All @@ -54,7 +76,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v3
- name: Setup system dependencies
Expand Down
24 changes: 13 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ repos:
hooks:
- id: pyupgrade
args: ["--py36-plus"]
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
- id: isort
name: isort (pyi)
types: [pyi]
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
Expand All @@ -31,12 +35,10 @@ repos:
- flake8-pyi==22.11.0
types: []
files: ^.*.pyi?$
- repo: local
hooks:
- id: mypy
name: mypy
entry: mypy
language: system
types: [ python ]
exclude: "scripts/*"
args: [ "--cache-dir=/dev/null", "--no-incremental" ]

ci:
autofix_commit_msg: '[pre-commit.ci] auto fixes from pre-commit.com hooks'
autofix_prs: true
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: weekly
submodules: false
7 changes: 4 additions & 3 deletions mypy_drf_plugin/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Dict, Optional
from typing import Callable, Dict, Optional, Type

from mypy.nodes import TypeInfo
from mypy.options import Options
Expand Down Expand Up @@ -28,9 +28,10 @@ def __init__(self, options: Options) -> None:
def _get_currently_defined_serializers(self) -> Dict[str, int]:
base_serializer_sym = self.lookup_fully_qualified(fullnames.BASE_SERIALIZER_FULLNAME)
if base_serializer_sym is not None and isinstance(base_serializer_sym.node, TypeInfo):
return base_serializer_sym.node.metadata.setdefault("drf", {}).setdefault(
serializer_bases: Dict[str, int] = base_serializer_sym.node.metadata.setdefault("drf", {}).setdefault(
"serializer_bases", {fullnames.BASE_SERIALIZER_FULLNAME: 1}
)
return serializer_bases
else:
return {}

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


def plugin(version):
def plugin(version: str) -> Type[NewSemanalDRFPlugin]:
return NewSemanalDRFPlugin
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
wheel
gitpython==3.1.30
gitpython==3.1.31
pre-commit==2.21.0
pytest==7.2.1
pytest-mypy-plugins==1.10.1
djangorestframework==3.14.0
types-pytz==2022.7.1.0
types-requests==2.28.11.8
types-urllib3==1.26.25.4
django-stubs==1.13.0
types-pytz==2022.7.1.2
types-requests==2.28.11.14
types-urllib3==1.26.25.7
django-stubs==1.15.0
django-stubs-ext==0.7.0
-e .[compatible-mypy,coreapi,markdown]
1 change: 0 additions & 1 deletion rest_framework-stubs/generics.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ from typing import Any, Protocol, TypeVar

from django.db.models import Manager, Model
from django.db.models.query import QuerySet

from rest_framework import mixins, views
from rest_framework.filters import BaseFilterBackend
from rest_framework.pagination import BasePagination
Expand Down
1 change: 0 additions & 1 deletion rest_framework-stubs/mixins.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any, TypeVar

from django.db.models import Model

from rest_framework.generics import UsesQuerySet
from rest_framework.request import Request
from rest_framework.response import Response
Expand Down
2 changes: 1 addition & 1 deletion rest_framework-stubs/permissions.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from collections.abc import Sequence
from typing import Any, Protocol, Union # noqa: Y037 # https://github.com/python/mypy/issues/12392
from typing_extensions import TypeAlias

from django.db.models import Model, QuerySet
from rest_framework.request import Request
from rest_framework.views import APIView
from typing_extensions import TypeAlias

SAFE_METHODS: Sequence[str]

Expand Down
2 changes: 1 addition & 1 deletion rest_framework-stubs/relations.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from collections import OrderedDict
from collections.abc import Callable, Iterable, Mapping, Sequence
from typing import Any, Generic, TypeVar
from _typeshed import Self

from _typeshed import Self
from django.db.models import Manager, Model, QuerySet
from rest_framework.fields import Field, Option
from rest_framework.request import Request
Expand Down
2 changes: 1 addition & 1 deletion rest_framework-stubs/renderers.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from json import JSONEncoder
from collections.abc import Iterable, Mapping, Sequence
from json import JSONEncoder
from typing import Any

from django import forms
Expand Down
5 changes: 2 additions & 3 deletions rest_framework-stubs/request.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from contextlib import contextmanager
from types import TracebackType
from collections.abc import Iterator, Sequence
from contextlib import AbstractContextManager
from contextlib import AbstractContextManager, contextmanager
from types import TracebackType
from typing import Any

from django.contrib.auth.base_user import AbstractBaseUser
Expand Down
3 changes: 1 addition & 2 deletions rest_framework-stubs/response.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ from collections.abc import Mapping
from typing import Any

from django.template.base import Template
from django.test.utils import ContextList
from django.template.response import SimpleTemplateResponse
from django.test.utils import ContextList
from django.urls import ResolverMatch

from rest_framework.request import Request
from rest_framework.test import APIClient

Expand Down
4 changes: 2 additions & 2 deletions rest_framework-stubs/schemas/generators.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from types import ModuleType
from collections.abc import Iterable, Sequence
from types import ModuleType
from typing import Any
from typing_extensions import TypeAlias

from django.db.models.base import Model
from rest_framework.compat import coreapi
from rest_framework.request import Request
from rest_framework.urlpatterns import _AnyURL
from rest_framework.views import APIView
from typing_extensions import TypeAlias

def common_path(paths: Iterable[str]) -> str: ...
def get_pk_name(model: type[Model]) -> str: ...
Expand Down
12 changes: 10 additions & 2 deletions rest_framework-stubs/test.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Iterable, Mapping
from typing import Any

import coreapi
Expand All @@ -13,6 +14,13 @@ from django.test.client import RequestFactory as DjangoRequestFactory
from rest_framework.authtoken.models import Token
from rest_framework.request import Request
from rest_framework.response import _MonkeyPatchedResponse
from typing_extensions import TypeAlias

_GetDataType: TypeAlias = (
Mapping[str, str | bytes | int | Iterable[str | bytes | int]]
| Iterable[tuple[str, str | bytes | int | Iterable[str | bytes | int]]]
| None
)

def force_authenticate(
request: HttpRequest, user: AnonymousUser | AbstractBaseUser | None = ..., token: Token | None = ...
Expand Down Expand Up @@ -50,7 +58,7 @@ class APIRequestFactory(DjangoRequestFactory):
renderer_classes: Any
def __init__(self, enforce_csrf_checks: bool = ..., **defaults: Any) -> None: ...
def request(self, **kwargs: Any) -> Request: ... # type: ignore[override]
def get(self, path: str, data: dict[str, Any] | str | None = ..., follow: bool = ..., **extra: Any) -> Request: ... # type: ignore[override]
def get(self, path: str, data: _GetDataType = ..., follow: bool = ..., **extra: Any) -> Request: ... # type: ignore[override]
def post(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> Request: ... # type: ignore[override]
def put(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> Request: ... # type: ignore[override]
def patch(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> Request: ... # type: ignore[override]
Expand All @@ -68,7 +76,7 @@ class APIClient(APIRequestFactory, DjangoClient):
def credentials(self, **kwargs: Any): ...
def force_authenticate(self, user: AnonymousUser | AbstractBaseUser = ..., token: Token | None = ...) -> None: ...
def request(self, **kwargs: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def get(self, path: str, data: dict[str, Any] | str | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def get(self, path: str, data: _GetDataType = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def post(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def put(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def patch(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
Expand Down
2 changes: 1 addition & 1 deletion rest_framework-stubs/urlpatterns.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections.abc import Iterable, Sequence
from typing_extensions import TypeAlias

from django.urls.resolvers import URLPattern, URLResolver
from typing_extensions import TypeAlias

_AnyURL: TypeAlias = URLPattern | URLResolver

Expand Down
4 changes: 2 additions & 2 deletions rest_framework-stubs/validators.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from collections.abc import Callable, Container, Iterable, MutableMapping
from typing import Any, TypeVar, Protocol
from typing_extensions import TypeAlias
from typing import Any, Protocol, TypeVar

from django.db.models import Model, QuerySet
from rest_framework.fields import Field
from rest_framework.serializers import BaseSerializer
from typing_extensions import TypeAlias

_T = TypeVar("_T", bound=Model)
_V = TypeVar("_V", contravariant=True)
Expand Down
2 changes: 1 addition & 1 deletion rest_framework-stubs/viewsets.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections import OrderedDict
from collections.abc import Callable
from typing import Any
from typing_extensions import TypeAlias

from django.http.request import HttpRequest
from django.http.response import HttpResponseBase
Expand All @@ -10,6 +9,7 @@ from rest_framework.decorators import ViewSetAction
from rest_framework.generics import _MT_co
from rest_framework.request import Request
from rest_framework.views import AsView, GenericView
from typing_extensions import TypeAlias

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

Expand Down
11 changes: 7 additions & 4 deletions scripts/git_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional
from typing import Optional, Union

from git import RemoteProgress, Repo
from git.remote import RemoteProgress
from git.repo import Repo

from scripts.paths import DRF_SOURCE_DIRECTORY

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

def update(self, op_code, cur_count, max_count=None, message=""):
def update(
self, op_code: int, cur_count: Union[str, float], max_count: Union[str, float, None] = None, message: str = ""
) -> None:
print(self._cur_line)


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

0 comments on commit 7bf13d6

Please sign in to comment.