Skip to content

Commit

Permalink
Merge branch 'master' into fix/strpromise
Browse files Browse the repository at this point in the history
  • Loading branch information
XF-FW authored Nov 18, 2022
2 parents 328c75d + 2584ad3 commit 45ab664
Show file tree
Hide file tree
Showing 72 changed files with 1,302 additions and 1,216 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/pre-commit-autoupdate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Run pre-commit autoupdate every day at midnight
# and create a pull request if any changes
# Copied from
# https://github.com/cookiecutter/cookiecutter-django

name: Pre-commit auto-update

on:
schedule:
- cron: "15 2 * * *"
workflow_dispatch: # to trigger manually

permissions:
contents: read

jobs:
auto-update:
# Disables this workflow from running in a repository that is not part of the indicated organization/user
if: github.repository_owner == 'typeddjango'
permissions:
contents: write # for peter-evans/create-pull-request to create branch
pull-requests: write # for peter-evans/create-pull-request to create a PR

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: Install pre-commit
run: pip install pre-commit

- name: Autoupdate deps
run: pre-commit autoupdate

- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: update/pre-commit-autoupdate
title: Auto-update pre-commit hooks
commit-message: Auto-update pre-commit hooks
body: Update versions of tools in pre-commit configs to latest version
labels: dependencies
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9']
python-version: ['3.10']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -31,13 +31,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9']
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- uses: actions/checkout@v3
- name: Setup system dependencies
run: sudo apt-get install binutils libproj-dev gdal-bin
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -52,13 +52,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9']
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- uses: actions/checkout@v3
- name: Setup system dependencies
run: sudo apt-get install binutils libproj-dev gdal-bin
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.egg-info
.DS_Store
.python-version
.idea/
.mypy_cache/
.pytest_cache/
Expand Down
14 changes: 9 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.3.0
hooks:
- id: check-yaml
- id: trailing-whitespace
Expand All @@ -11,7 +11,7 @@ repos:
- id: check-merge-conflict
- id: end-of-file-fixer
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
rev: v3.2.2
hooks:
- id: pyupgrade
args: ["--py36-plus"]
Expand All @@ -20,13 +20,17 @@ repos:
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 22.10.0
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies:
- flake8-pyi==22.10.0
types: []
files: ^.*.pyi?$
- repo: local
hooks:
- id: mypy
Expand Down
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ This project is open source and community driven. As such we encourage code cont
4. Write tests
5. Update dependencies

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

## Tutorials

If you want to start working on this project, you will need to get familiar with python typings.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
[![Gitter](https://badges.gitter.im/mypy-django/Lobby.svg)](https://gitter.im/mypy-django/Lobby)


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

## Installation

```bash
pip install djangorestframework-stubs
pip install djangorestframework-stubs[compatible-mypy]
```

To make mypy aware of the plugin, you need to add
Expand Down
3 changes: 2 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
strict_optional = True
ignore_missing_imports = True
check_untyped_defs = True
warn_no_return = False
show_traceback = True
allow_redefinition = True
incremental = True
show_error_codes = False
disable_error_code = empty-body

plugins =
mypy_django_plugin.main,
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ line_length = 120
multi_line_output = 3
include_trailing_comma = true
profile = 'black'

[build-system]
requires = ["setuptools<64", "wheel"]
16 changes: 9 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
wheel
gitpython==3.1.27
pre-commit==2.19.0
pytest==7.1.2
pytest-mypy-plugins==1.9.3
djangorestframework==3.13.1
types-pytz==2021.3.8
-e .
gitpython==3.1.29
pre-commit==2.20.0
pytest==7.2.0
pytest-mypy-plugins==1.10.1
djangorestframework==3.14.0
types-pytz==2022.6.0.1
django-stubs==1.13.0
django-stubs-ext==0.7.0
-e .[compatible-mypy,coreapi,markdown]
22 changes: 11 additions & 11 deletions rest_framework-stubs/authentication.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional, Tuple, Type
from typing import Any

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

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

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

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

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

class RemoteUserAuthentication(BaseAuthentication):
header: str = ...
header: str
2 changes: 1 addition & 1 deletion rest_framework-stubs/authtoken/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
default_app_config: str = ...
default_app_config: str
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from django.core.management.base import BaseCommand
UserModel: AbstractBaseUser

class Command(BaseCommand):
help: str = ...
help: str
def create_user_token(self, username: str, reset_token: bool): ...
def add_arguments(self, parser: Any) -> None: ...
def handle(self, *args: Any, **options: Any) -> None: ...
6 changes: 3 additions & 3 deletions rest_framework-stubs/authtoken/models.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ from typing import Any
from django.db import models

class Token(models.Model):
key: models.CharField = ...
user: models.OneToOneField = ...
created: models.DateTimeField = ...
key: models.CharField
user: models.OneToOneField
created: models.DateTimeField
@classmethod
def generate_key(cls) -> str: ...

Expand Down
6 changes: 3 additions & 3 deletions rest_framework-stubs/authtoken/serializers.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import serializers

class AuthTokenSerializer(serializers.Serializer):
username: serializers.CharField = ...
password: serializers.CharField = ...
token: serializers.CharField = ...
username: serializers.CharField
password: serializers.CharField
token: serializers.CharField
6 changes: 3 additions & 3 deletions rest_framework-stubs/authtoken/views.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Any, Type
from typing import Any

from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.serializers import Serializer
from rest_framework.views import APIView, AsView, GenericView

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

obtain_auth_token: AsView[GenericView] = ...
obtain_auth_token: AsView[GenericView]
4 changes: 2 additions & 2 deletions rest_framework-stubs/checks.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from typing import Any, List
from typing import Any

def pagination_system_check(app_configs: Any, **kwargs: Any) -> List[Any]: ...
def pagination_system_check(app_configs: Any, **kwargs: Any) -> list[Any]: ...
27 changes: 15 additions & 12 deletions rest_framework-stubs/compat.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from typing import Any, Optional, Tuple, Union
from typing import Any

import coreapi # noqa: F401
import requests # noqa: F401
from django.db.models import QuerySet

try:
from django.contrib.postgres import fields as postgres_fields
except ImportError:
postgres_fields = None # type: ignore
try:
import coreapi
except ImportError:
coreapi = None # type: ignore
try:
import uritemplate
except ImportError:
Expand All @@ -29,30 +32,30 @@ try:
except ImportError:
pygments = None # type: ignore
try:
import markdown
import markdown # type: ignore
def apply_markdown(text: str): ...

except ImportError:
apply_markdown = None # type: ignore
markdown = None # type: ignore

if markdown is not None and pygments is not None:
from markdown.preprocessors import Preprocessor
from markdown.preprocessors import Preprocessor # type: ignore

class CodeBlockPreprocessor(Preprocessor):
pattern: Any = ...
formatter: Any = ...
pattern: Any
formatter: Any
def run(self, lines: Any): ...

def pygments_css(style: Any) -> Optional[str]: ...
def pygments_css(style: Any) -> str | None: ...
def pygments_highlight(text: str, lang: str, style: Any) -> Any: ...
def md_filter_add_syntax_highlight(md: Any) -> bool: ...
def unicode_http_header(value: Union[str, bytes]) -> str: ...
def distinct(queryset: QuerySet, base: Optional[QuerySet]) -> QuerySet: ...
def unicode_http_header(value: str | bytes) -> str: ...
def distinct(queryset: QuerySet, base: QuerySet | None) -> QuerySet: ...

SHORT_SEPARATORS: Tuple[str, str]
LONG_SEPARATORS: Tuple[str, str]
INDENT_SEPARATORS: Tuple[str, str]
SHORT_SEPARATORS: tuple[str, str]
LONG_SEPARATORS: tuple[str, str]
INDENT_SEPARATORS: tuple[str, str]

__all__ = [
"coreapi",
Expand Down
Loading

0 comments on commit 45ab664

Please sign in to comment.