Skip to content

Commit 45ab664

Browse files
authored
Merge branch 'master' into fix/strpromise
2 parents 328c75d + 2584ad3 commit 45ab664

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1302
-1216
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Run pre-commit autoupdate every day at midnight
2+
# and create a pull request if any changes
3+
# Copied from
4+
# https://github.com/cookiecutter/cookiecutter-django
5+
6+
name: Pre-commit auto-update
7+
8+
on:
9+
schedule:
10+
- cron: "15 2 * * *"
11+
workflow_dispatch: # to trigger manually
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
auto-update:
18+
# Disables this workflow from running in a repository that is not part of the indicated organization/user
19+
if: github.repository_owner == 'typeddjango'
20+
permissions:
21+
contents: write # for peter-evans/create-pull-request to create branch
22+
pull-requests: write # for peter-evans/create-pull-request to create a PR
23+
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v3
27+
- uses: actions/setup-python@v4
28+
with:
29+
python-version: "3.9"
30+
31+
- name: Install pre-commit
32+
run: pip install pre-commit
33+
34+
- name: Autoupdate deps
35+
run: pre-commit autoupdate
36+
37+
- name: Create Pull Request
38+
uses: peter-evans/create-pull-request@v4
39+
with:
40+
token: ${{ secrets.GITHUB_TOKEN }}
41+
branch: update/pre-commit-autoupdate
42+
title: Auto-update pre-commit hooks
43+
commit-message: Auto-update pre-commit hooks
44+
body: Update versions of tools in pre-commit configs to latest version
45+
labels: dependencies

.github/workflows/test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
python-version: ['3.9']
15+
python-version: ['3.10']
1616
steps:
1717
- uses: actions/checkout@v3
1818
- name: Set up Python ${{ matrix.python-version }}
19-
uses: actions/setup-python@v3
19+
uses: actions/setup-python@v4
2020
with:
2121
python-version: ${{ matrix.python-version }}
2222
- name: Install dependencies
@@ -31,13 +31,13 @@ jobs:
3131
runs-on: ubuntu-latest
3232
strategy:
3333
matrix:
34-
python-version: ['3.7', '3.8', '3.9']
34+
python-version: ['3.7', '3.8', '3.9', '3.10']
3535
steps:
3636
- uses: actions/checkout@v3
3737
- name: Setup system dependencies
3838
run: sudo apt-get install binutils libproj-dev gdal-bin
3939
- name: Set up Python ${{ matrix.python-version }}
40-
uses: actions/setup-python@v3
40+
uses: actions/setup-python@v4
4141
with:
4242
python-version: ${{ matrix.python-version }}
4343
- name: Install dependencies
@@ -52,13 +52,13 @@ jobs:
5252
runs-on: ubuntu-latest
5353
strategy:
5454
matrix:
55-
python-version: ['3.7', '3.8', '3.9']
55+
python-version: ['3.7', '3.8', '3.9', '3.10']
5656
steps:
5757
- uses: actions/checkout@v3
5858
- name: Setup system dependencies
5959
run: sudo apt-get install binutils libproj-dev gdal-bin
6060
- name: Set up Python ${{ matrix.python-version }}
61-
uses: actions/setup-python@v3
61+
uses: actions/setup-python@v4
6262
with:
6363
python-version: ${{ matrix.python-version }}
6464
- name: Install dependencies

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.egg-info
22
.DS_Store
3+
.python-version
34
.idea/
45
.mypy_cache/
56
.pytest_cache/

.pre-commit-config.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.1.0
5+
rev: v4.3.0
66
hooks:
77
- id: check-yaml
88
- id: trailing-whitespace
@@ -11,7 +11,7 @@ repos:
1111
- id: check-merge-conflict
1212
- id: end-of-file-fixer
1313
- repo: https://github.com/asottile/pyupgrade
14-
rev: v2.31.1
14+
rev: v3.2.2
1515
hooks:
1616
- id: pyupgrade
1717
args: ["--py36-plus"]
@@ -20,13 +20,17 @@ repos:
2020
hooks:
2121
- id: isort
2222
- repo: https://github.com/psf/black
23-
rev: 22.3.0
23+
rev: 22.10.0
2424
hooks:
2525
- id: black
26-
- repo: https://gitlab.com/pycqa/flake8
27-
rev: 3.9.2
26+
- repo: https://github.com/PyCQA/flake8
27+
rev: 5.0.4
2828
hooks:
2929
- id: flake8
30+
additional_dependencies:
31+
- flake8-pyi==22.10.0
32+
types: []
33+
files: ^.*.pyi?$
3034
- repo: local
3135
hooks:
3236
- id: mypy

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ This project is open source and community driven. As such we encourage code cont
88
4. Write tests
99
5. Update dependencies
1010

11+
Type stubs in `.pyi` files should follow
12+
[coding conventions from typeshed project](https://github.com/python/typeshed/blob/main/CONTRIBUTING.md#conventions).
13+
1114
## Tutorials
1215

1316
If you want to start working on this project, you will need to get familiar with python typings.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
[![Gitter](https://badges.gitter.im/mypy-django/Lobby.svg)](https://gitter.im/mypy-django/Lobby)
88

99

10-
Mypy stubs for [DRF 3.12.x](https://pypi.org/project/djangorestframework/).
11-
Supports Python 3.6, 3.7, 3.8 and 3.9.
10+
Mypy stubs for [Django REST Framework](https://pypi.org/project/djangorestframework/).
11+
Supports Python 3.7 and up.
1212

1313
## Installation
1414

1515
```bash
16-
pip install djangorestframework-stubs
16+
pip install djangorestframework-stubs[compatible-mypy]
1717
```
1818

1919
To make mypy aware of the plugin, you need to add

mypy.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
strict_optional = True
33
ignore_missing_imports = True
44
check_untyped_defs = True
5-
warn_no_return = False
65
show_traceback = True
76
allow_redefinition = True
87
incremental = True
8+
show_error_codes = False
9+
disable_error_code = empty-body
910

1011
plugins =
1112
mypy_django_plugin.main,

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ line_length = 120
77
multi_line_output = 3
88
include_trailing_comma = true
99
profile = 'black'
10+
11+
[build-system]
12+
requires = ["setuptools<64", "wheel"]

requirements.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
wheel
2-
gitpython==3.1.27
3-
pre-commit==2.19.0
4-
pytest==7.1.2
5-
pytest-mypy-plugins==1.9.3
6-
djangorestframework==3.13.1
7-
types-pytz==2021.3.8
8-
-e .
2+
gitpython==3.1.29
3+
pre-commit==2.20.0
4+
pytest==7.2.0
5+
pytest-mypy-plugins==1.10.1
6+
djangorestframework==3.14.0
7+
types-pytz==2022.6.0.1
8+
django-stubs==1.13.0
9+
django-stubs-ext==0.7.0
10+
-e .[compatible-mypy,coreapi,markdown]
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Optional, Tuple, Type
1+
from typing import Any
22

33
from django.contrib.auth import authenticate as authenticate
44
from django.db.models import Model
@@ -10,23 +10,23 @@ def get_authorization_header(request: Request) -> bytes: ...
1010
class CSRFCheck(CsrfViewMiddleware): ...
1111

1212
class BaseAuthentication:
13-
def authenticate(self, request: Request) -> Optional[Tuple[Any, Any]]: ...
14-
def authenticate_header(self, request: Request) -> Optional[str]: ...
13+
def authenticate(self, request: Request) -> tuple[Any, Any] | None: ... # noqa: F811
14+
def authenticate_header(self, request: Request) -> str | None: ...
1515

1616
class BasicAuthentication(BaseAuthentication):
17-
www_authenticate_realm: str = ...
17+
www_authenticate_realm: str
1818
def authenticate_credentials(
19-
self, userid: str, password: str, request: Optional[Request] = ...
20-
) -> Tuple[Any, None]: ...
19+
self, userid: str, password: str, request: Request | None = ...
20+
) -> tuple[Any, None]: ...
2121

2222
class SessionAuthentication(BaseAuthentication):
2323
def enforce_csrf(self, request: Request) -> None: ...
2424

2525
class TokenAuthentication(BaseAuthentication):
26-
keyword: str = ...
27-
model: Optional[Type[Model]] = ...
28-
def get_model(self) -> Type[Model]: ...
29-
def authenticate_credentials(self, key: str) -> Tuple[Any, Any]: ...
26+
keyword: str
27+
model: type[Model] | None
28+
def get_model(self) -> type[Model]: ...
29+
def authenticate_credentials(self, key: str) -> tuple[Any, Any]: ...
3030

3131
class RemoteUserAuthentication(BaseAuthentication):
32-
header: str = ...
32+
header: str
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
default_app_config: str = ...
1+
default_app_config: str

rest_framework-stubs/authtoken/management/commands/drf_create_token.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from django.core.management.base import BaseCommand
66
UserModel: AbstractBaseUser
77

88
class Command(BaseCommand):
9-
help: str = ...
9+
help: str
1010
def create_user_token(self, username: str, reset_token: bool): ...
1111
def add_arguments(self, parser: Any) -> None: ...
1212
def handle(self, *args: Any, **options: Any) -> None: ...

rest_framework-stubs/authtoken/models.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ from typing import Any
33
from django.db import models
44

55
class Token(models.Model):
6-
key: models.CharField = ...
7-
user: models.OneToOneField = ...
8-
created: models.DateTimeField = ...
6+
key: models.CharField
7+
user: models.OneToOneField
8+
created: models.DateTimeField
99
@classmethod
1010
def generate_key(cls) -> str: ...
1111

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from rest_framework import serializers
22

33
class AuthTokenSerializer(serializers.Serializer):
4-
username: serializers.CharField = ...
5-
password: serializers.CharField = ...
6-
token: serializers.CharField = ...
4+
username: serializers.CharField
5+
password: serializers.CharField
6+
token: serializers.CharField
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from typing import Any, Type
1+
from typing import Any
22

33
from rest_framework.request import Request
44
from rest_framework.response import Response
55
from rest_framework.serializers import Serializer
66
from rest_framework.views import APIView, AsView, GenericView
77

88
class ObtainAuthToken(APIView):
9-
serializer_class: Type[Serializer] = ...
9+
serializer_class: type[Serializer]
1010
def post(self, request: Request, *args: Any, **kwargs: Any) -> Response: ...
1111

12-
obtain_auth_token: AsView[GenericView] = ...
12+
obtain_auth_token: AsView[GenericView]

rest_framework-stubs/checks.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from typing import Any, List
1+
from typing import Any
22

3-
def pagination_system_check(app_configs: Any, **kwargs: Any) -> List[Any]: ...
3+
def pagination_system_check(app_configs: Any, **kwargs: Any) -> list[Any]: ...

rest_framework-stubs/compat.pyi

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
from typing import Any, Optional, Tuple, Union
1+
from typing import Any
22

3-
import coreapi # noqa: F401
43
import requests # noqa: F401
54
from django.db.models import QuerySet
65

76
try:
87
from django.contrib.postgres import fields as postgres_fields
98
except ImportError:
109
postgres_fields = None # type: ignore
10+
try:
11+
import coreapi
12+
except ImportError:
13+
coreapi = None # type: ignore
1114
try:
1215
import uritemplate
1316
except ImportError:
@@ -29,30 +32,30 @@ try:
2932
except ImportError:
3033
pygments = None # type: ignore
3134
try:
32-
import markdown
35+
import markdown # type: ignore
3336
def apply_markdown(text: str): ...
3437

3538
except ImportError:
3639
apply_markdown = None # type: ignore
3740
markdown = None # type: ignore
3841

3942
if markdown is not None and pygments is not None:
40-
from markdown.preprocessors import Preprocessor
43+
from markdown.preprocessors import Preprocessor # type: ignore
4144

4245
class CodeBlockPreprocessor(Preprocessor):
43-
pattern: Any = ...
44-
formatter: Any = ...
46+
pattern: Any
47+
formatter: Any
4548
def run(self, lines: Any): ...
4649

47-
def pygments_css(style: Any) -> Optional[str]: ...
50+
def pygments_css(style: Any) -> str | None: ...
4851
def pygments_highlight(text: str, lang: str, style: Any) -> Any: ...
4952
def md_filter_add_syntax_highlight(md: Any) -> bool: ...
50-
def unicode_http_header(value: Union[str, bytes]) -> str: ...
51-
def distinct(queryset: QuerySet, base: Optional[QuerySet]) -> QuerySet: ...
53+
def unicode_http_header(value: str | bytes) -> str: ...
54+
def distinct(queryset: QuerySet, base: QuerySet | None) -> QuerySet: ...
5255

53-
SHORT_SEPARATORS: Tuple[str, str]
54-
LONG_SEPARATORS: Tuple[str, str]
55-
INDENT_SEPARATORS: Tuple[str, str]
56+
SHORT_SEPARATORS: tuple[str, str]
57+
LONG_SEPARATORS: tuple[str, str]
58+
INDENT_SEPARATORS: tuple[str, str]
5659

5760
__all__ = [
5861
"coreapi",

0 commit comments

Comments
 (0)