Skip to content

Commit

Permalink
Better linting config (typeddjango#664)
Browse files Browse the repository at this point in the history
* Better linting config

* Applies isort on django-stubs, only style changes

* Fixes black and isort compat
  • Loading branch information
sobolevn committed Jul 4, 2021
1 parent 552f2ff commit d5e45db
Show file tree
Hide file tree
Showing 288 changed files with 1,155 additions and 1,198 deletions.
16 changes: 11 additions & 5 deletions .pre-commit-config.yaml
Expand Up @@ -4,28 +4,34 @@ default_language_version:
python: python3.9
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
rev: v4.0.1
hooks:
- id: check-yaml
- id: trailing-whitespace
- id: check-executables-have-shebangs
- id: debug-statements
- id: check-merge-conflict
- repo: https://github.com/asottile/pyupgrade
rev: v2.7.3
rev: v2.20.0
hooks:
- id: pyupgrade
args: ["--py36-plus"]
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.6.4
rev: v5.9.1
hooks:
- id: isort
name: isort (python)
args: ["--profile", "black"]
- id: isort
name: isort (pyi)
types: [pyi]
args: ["--profile", "black"]
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 21.6b0
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
rev: 3.9.2
hooks:
- id: flake8
- repo: local
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Expand Up @@ -3,7 +3,7 @@ black==21.6b0
requests==2.24.0
coreapi==2.3.3
gitpython==3.1.9
pre-commit==2.7.1
pre-commit==2.13.0
pytest==6.1.1
pytest-mypy-plugins==1.7.0
psycopg2-binary
Expand Down
1 change: 1 addition & 0 deletions django-stubs/__init__.pyi
@@ -1,4 +1,5 @@
from typing import Any, NamedTuple

from .utils.version import get_version as get_version

VERSION: Any
Expand Down
1 change: 0 additions & 1 deletion django-stubs/apps/__init__.pyi
@@ -1,3 +1,2 @@
from .config import AppConfig as AppConfig

from .registry import apps as apps
2 changes: 1 addition & 1 deletion django-stubs/apps/config.pyi
@@ -1,4 +1,4 @@
from typing import Any, Iterator, Type, Optional, Dict
from typing import Any, Dict, Iterator, Optional, Type

from django.apps.registry import Apps
from django.db.models.base import Model
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/conf/locale/__init__.pyi
@@ -1,3 +1,3 @@
from typing import Dict, Any
from typing import Any, Dict

LANG_INFO: Dict[str, Any] = ...
5 changes: 2 additions & 3 deletions django-stubs/conf/urls/__init__.pyi
@@ -1,9 +1,8 @@
# Stubs for django.conf.urls (Python 3.5)
from typing import Any, Callable, Dict, Optional, overload, Sequence, Tuple, Union
from typing import Any, Callable, Dict, Optional, Sequence, Tuple, Union, overload

from django.http.response import HttpResponse, HttpResponseBase

from django.urls import URLResolver, URLPattern
from django.urls import URLPattern, URLResolver

handler400: Union[str, Callable[..., HttpResponse]] = ...
handler403: Union[str, Callable[..., HttpResponse]] = ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/conf/urls/i18n.pyi
@@ -1,4 +1,4 @@
from typing import Any, List, Tuple, Callable
from typing import Any, Callable, List, Tuple

from django.urls.resolvers import URLPattern

Expand Down
42 changes: 20 additions & 22 deletions django-stubs/contrib/admin/__init__.pyi
@@ -1,25 +1,23 @@
from .decorators import action as action, register as register
from .filters import (
AllValuesFieldListFilter as AllValuesFieldListFilter,
BooleanFieldListFilter as BooleanFieldListFilter,
ChoicesFieldListFilter as ChoicesFieldListFilter,
DateFieldListFilter as DateFieldListFilter,
FieldListFilter as FieldListFilter,
ListFilter as ListFilter,
RelatedFieldListFilter as RelatedFieldListFilter,
RelatedOnlyFieldListFilter as RelatedOnlyFieldListFilter,
SimpleListFilter as SimpleListFilter,
EmptyFieldListFilter as EmptyFieldListFilter,
)
from .helpers import ACTION_CHECKBOX_NAME as ACTION_CHECKBOX_NAME
from .options import (
HORIZONTAL as HORIZONTAL,
VERTICAL as VERTICAL,
ModelAdmin as ModelAdmin,
StackedInline as StackedInline,
TabularInline as TabularInline,
)
from .sites import AdminSite as AdminSite, site as site
from . import checks as checks
from .decorators import action as action
from .decorators import register as register
from .filters import AllValuesFieldListFilter as AllValuesFieldListFilter
from .filters import BooleanFieldListFilter as BooleanFieldListFilter
from .filters import ChoicesFieldListFilter as ChoicesFieldListFilter
from .filters import DateFieldListFilter as DateFieldListFilter
from .filters import EmptyFieldListFilter as EmptyFieldListFilter
from .filters import FieldListFilter as FieldListFilter
from .filters import ListFilter as ListFilter
from .filters import RelatedFieldListFilter as RelatedFieldListFilter
from .filters import RelatedOnlyFieldListFilter as RelatedOnlyFieldListFilter
from .filters import SimpleListFilter as SimpleListFilter
from .helpers import ACTION_CHECKBOX_NAME as ACTION_CHECKBOX_NAME
from .options import HORIZONTAL as HORIZONTAL
from .options import VERTICAL as VERTICAL
from .options import ModelAdmin as ModelAdmin
from .options import StackedInline as StackedInline
from .options import TabularInline as TabularInline
from .sites import AdminSite as AdminSite
from .sites import site as site

def autodiscover() -> None: ...
3 changes: 1 addition & 2 deletions django-stubs/contrib/admin/checks.pyi
@@ -1,10 +1,9 @@
from typing import Any, List, Optional, Sequence

from django.apps.config import AppConfig
from django.contrib.admin.options import BaseModelAdmin
from django.core.checks.messages import CheckMessage, Error

from django.apps.config import AppConfig

def check_admin_app(app_configs: Optional[Sequence[AppConfig]] = ..., **kwargs: Any) -> List[Error]: ...
def check_dependencies(app_configs: Optional[Sequence[AppConfig]] = ..., **kwargs: Any) -> List[Error]: ...

Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/admin/decorators.pyi
@@ -1,4 +1,4 @@
from typing import Callable, Optional, Type, Sequence, Union, TypeVar, Any
from typing import Any, Callable, Optional, Sequence, Type, TypeVar, Union

from django.contrib.admin import ModelAdmin
from django.contrib.admin.sites import AdminSite
Expand Down
5 changes: 2 additions & 3 deletions django-stubs/contrib/admin/filters.pyi
@@ -1,13 +1,12 @@
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Iterator
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Type

from django.contrib.admin.options import ModelAdmin
from django.core.handlers.wsgi import WSGIRequest
from django.db.models.base import Model
from django.db.models.fields import Field
from django.db.models.fields.related import RelatedField
from django.db.models.query import QuerySet

from django.db.models.fields import Field

class ListFilter:
title: Any = ...
template: str = ...
Expand Down
7 changes: 3 additions & 4 deletions django-stubs/contrib/admin/helpers.pyi
@@ -1,14 +1,13 @@
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union, Iterable
from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple, Union

from django import forms
from django.db.models.fields import AutoField
from django.forms.boundfield import BoundField
from django.forms.forms import BaseForm
from django.forms.utils import ErrorDict
from django.forms.widgets import Media, Widget
from django.utils.safestring import SafeText

from django import forms
from django.db.models.fields import AutoField

ACTION_CHECKBOX_NAME: str

class ActionForm(forms.Form):
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/contrib/admin/models.pyi
Expand Up @@ -2,9 +2,8 @@ from typing import Any, Optional, Union
from uuid import UUID

from django.contrib.contenttypes.models import ContentType
from django.db.models.base import Model

from django.db import models
from django.db.models.base import Model

ADDITION: int
CHANGE: int
Expand Down
15 changes: 6 additions & 9 deletions django-stubs/contrib/admin/options.pyi
Expand Up @@ -6,20 +6,16 @@ from typing import (
Generic,
Iterator,
List,
Mapping,
Optional,
Sequence,
Set,
Tuple,
Type,
Union,
Mapping,
TypeVar,
Union,
)

from django.forms.forms import BaseForm
from django.forms.models import BaseInlineFormSet
from typing_extensions import Literal, TypedDict

from django.contrib.admin.filters import ListFilter
from django.contrib.admin.models import LogEntry
from django.contrib.admin.sites import AdminSite
Expand All @@ -29,19 +25,20 @@ from django.contrib.contenttypes.models import ContentType
from django.core.checks.messages import CheckMessage
from django.core.paginator import Paginator
from django.db.models.base import Model
from django.db.models.fields import Field
from django.db.models.fields.related import ForeignKey, ManyToManyField, RelatedField
from django.db.models.options import Options
from django.db.models.query import QuerySet
from django.forms.fields import TypedChoiceField
from django.forms.models import ModelChoiceField, ModelMultipleChoiceField
from django.forms.forms import BaseForm
from django.forms.models import BaseInlineFormSet, ModelChoiceField, ModelMultipleChoiceField
from django.forms.widgets import Media
from django.http.request import HttpRequest
from django.http.response import HttpResponse, HttpResponseBase, HttpResponseRedirect, JsonResponse
from django.template.response import TemplateResponse
from django.urls.resolvers import URLPattern
from django.utils.safestring import SafeText

from django.db.models.fields import Field
from typing_extensions import Literal, TypedDict

IS_POPUP_VAR: str
TO_FIELD_VAR: str
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/admin/sites.pyi
Expand Up @@ -4,14 +4,14 @@ from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type, U
from django.apps.config import AppConfig
from django.contrib.admin.options import ModelAdmin
from django.contrib.auth.forms import AuthenticationForm
from django.core.checks import CheckMessage
from django.core.handlers.wsgi import WSGIRequest
from django.db.models.base import Model
from django.db.models.query import QuerySet
from django.http.response import HttpResponse
from django.template.response import TemplateResponse
from django.urls import URLResolver, URLPattern
from django.urls import URLPattern, URLResolver
from django.utils.functional import LazyObject
from django.core.checks import CheckMessage

if sys.version_info >= (3, 9):
from weakref import WeakSet
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/admin/templatetags/admin_list.pyi
@@ -1,4 +1,4 @@
from typing import Any, Dict, Iterator, List, Optional, Union, Iterable
from typing import Any, Dict, Iterable, Iterator, List, Optional, Union

from django.contrib.admin.filters import FieldListFilter
from django.contrib.admin.templatetags.base import InclusionAdminNode
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/contrib/admin/utils.pyi
Expand Up @@ -9,13 +9,12 @@ from django.contrib.auth.forms import AdminPasswordChangeForm
from django.core.handlers.wsgi import WSGIRequest
from django.db.models.base import Model
from django.db.models.deletion import Collector
from django.db.models.fields import Field, reverse_related
from django.db.models.fields.reverse_related import ManyToOneRel
from django.db.models.options import Options
from django.db.models.query import QuerySet
from django.forms.forms import BaseForm

from django.db.models.fields import Field, reverse_related

class FieldIsAForeignKeyColumnName(Exception): ...

def lookup_needs_distinct(opts: Options, lookup_path: str) -> bool: ...
Expand Down
11 changes: 4 additions & 7 deletions django-stubs/contrib/admin/views/main.pyi
Expand Up @@ -2,17 +2,14 @@ from collections import OrderedDict
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union

from django.contrib.admin.filters import ListFilter, SimpleListFilter
from django.contrib.admin.options import ( # noqa: F401
ModelAdmin,
IS_POPUP_VAR as IS_POPUP_VAR,
TO_FIELD_VAR as TO_FIELD_VAR,
)
from django.contrib.admin.options import IS_POPUP_VAR as IS_POPUP_VAR # noqa: F401
from django.contrib.admin.options import TO_FIELD_VAR as TO_FIELD_VAR
from django.contrib.admin.options import ModelAdmin
from django.core.handlers.wsgi import WSGIRequest
from django.db.models.base import Model
from django.db.models.expressions import Combinable, CombinedExpression, OrderBy
from django.db.models.query import QuerySet

from django.db.models.options import Options
from django.db.models.query import QuerySet
from django.forms.formsets import BaseFormSet

ALL_VAR: str
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/contrib/admin/widgets.pyi
@@ -1,13 +1,12 @@
from typing import Any, Dict, Optional, Tuple, Union
from uuid import UUID

from django import forms
from django.contrib.admin.sites import AdminSite
from django.db.models.fields.reverse_related import ForeignObjectRel, ManyToOneRel
from django.forms.models import ModelChoiceIterator
from django.forms.widgets import Media

from django import forms

class FilteredSelectMultiple(forms.SelectMultiple):
@property
def media(self) -> Media: ...
Expand Down
3 changes: 2 additions & 1 deletion django-stubs/contrib/admindocs/apps.pyi
@@ -1,6 +1,7 @@
from django.apps import AppConfig as AppConfig
from typing import Any

from django.apps import AppConfig as AppConfig

class AdminDocsConfig(AppConfig):
name: str = ...
verbose_name: Any = ...
3 changes: 1 addition & 2 deletions django-stubs/contrib/auth/admin.pyi
@@ -1,10 +1,9 @@
from typing import Any

from django.contrib import admin
from django.core.handlers.wsgi import WSGIRequest
from django.http.response import HttpResponse

from django.contrib import admin

csrf_protect_m: Any
sensitive_post_parameters_m: Any

Expand Down
3 changes: 1 addition & 2 deletions django-stubs/contrib/auth/backends.pyi
@@ -1,8 +1,7 @@
from typing import Any, Optional, Set, Union

from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.models import AnonymousUser, User, Permission

from django.contrib.auth.models import AnonymousUser, Permission, User
from django.db.models.base import Model
from django.http.request import HttpRequest

Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/auth/base_user.pyi
@@ -1,10 +1,10 @@
import sys
from typing import Any, Optional, Tuple, List, overload, TypeVar, Union
from typing import Any, List, Optional, Tuple, TypeVar, Union, overload

from django.db import models
from django.db.models.base import Model
from django.db.models.expressions import Combinable
from django.db.models.fields import BooleanField
from django.db import models

if sys.version_info < (3, 8):
from typing_extensions import Literal
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/contrib/auth/checks.pyi
@@ -1,8 +1,7 @@
from typing import Any, List, Optional, Sequence

from django.core.checks.messages import CheckMessage

from django.apps.config import AppConfig
from django.core.checks.messages import CheckMessage

def check_user_model(app_configs: Optional[Sequence[AppConfig]] = ..., **kwargs: Any) -> List[CheckMessage]: ...
def check_models_permissions(app_configs: Optional[Sequence[AppConfig]] = ..., **kwargs: Any) -> List[CheckMessage]: ...
5 changes: 2 additions & 3 deletions django-stubs/contrib/auth/decorators.pyi
@@ -1,9 +1,8 @@
from typing import Callable, List, Optional, Set, Union, TypeVar, overload
from typing import Callable, List, Optional, Set, TypeVar, Union, overload

from django.contrib.auth import REDIRECT_FIELD_NAME as REDIRECT_FIELD_NAME # noqa: F401
from django.http.response import HttpResponseBase

from django.contrib.auth.models import AbstractUser
from django.http.response import HttpResponseBase

_VIEW = TypeVar("_VIEW", bound=Callable[..., HttpResponseBase])

Expand Down
3 changes: 1 addition & 2 deletions django-stubs/contrib/auth/forms.pyi
@@ -1,13 +1,12 @@
from typing import Any, Dict, Iterator, Optional

from django import forms
from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.models import User
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.core.exceptions import ValidationError
from django.core.handlers.wsgi import WSGIRequest

from django import forms

UserModel: Any

class ReadOnlyPasswordHashWidget(forms.Widget):
Expand Down

0 comments on commit d5e45db

Please sign in to comment.