Skip to content

Commit

Permalink
add linting stubs with flake8-pyi and check for unused imports (typed…
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurnikov authored Sep 24, 2019
1 parent 7407b93 commit 963d50c
Show file tree
Hide file tree
Showing 91 changed files with 139 additions and 176 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ jobs:
python: 3.7
script: 'flake8'

- name: Lint stubs with flake8-pyi and check for unused imports
python: 3.7
script: 'flake8 --config flake8-pyi.ini'

- name: Lint plugin code with isort
python: 3.7
script: 'isort --check --diff'
Expand Down
3 changes: 2 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
black
pytest-mypy-plugins==1.0.3
psycopg2
flake8
flake8==3.7.8
flake8-pyi==19.3.0
isort==4.3.21
-e .
6 changes: 3 additions & 3 deletions django-stubs/apps/registry.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import threading
from collections import OrderedDict
from typing import Any, Callable, List, Optional, Tuple, Type, Union, Iterable, DefaultDict, Dict
from typing import Any, Callable, DefaultDict, Dict, Iterable, List, Optional, Tuple, Type, Union

from django.db.migrations.state import AppConfigStub
from django.db.models.base import Model

from .config import AppConfig

class Apps:
all_models: "Dict[str, OrderedDict[str, Type[Model]]]" = ...
app_configs: "OrderedDict[str, AppConfig]" = ...
all_models: Dict[str, OrderedDict[str, Type[Model]]] = ...
app_configs: OrderedDict[str, AppConfig] = ...
stored_app_configs: List[Any] = ...
apps_ready: bool = ...
ready_event: threading.Event = ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/admin/checks.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, List, Union

from django.contrib.admin.options import BaseModelAdmin, InlineModelAdmin, ModelAdmin
from django.contrib.admin.options import BaseModelAdmin
from django.core.checks.messages import Error

_CheckError = Union[str, Error]
Expand Down
3 changes: 1 addition & 2 deletions django-stubs/contrib/admin/templatetags/admin_modify.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any, Optional
from typing import Any

from django.contrib.admin.helpers import InlineAdminForm
from django.contrib.admin.templatetags.base import InclusionAdminNode
from django.template.base import Parser, Token
from django.template.context import Context, RequestContext

Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/admin/templatetags/admin_static.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Any

register: Any

Expand Down
6 changes: 5 additions & 1 deletion django-stubs/contrib/admin/views/main.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ 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 ModelAdmin, IS_POPUP_VAR as IS_POPUP_VAR, TO_FIELD_VAR as TO_FIELD_VAR
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.core.handlers.wsgi import WSGIRequest
from django.db.models.base import Model
from django.db.models.expressions import Combinable, CombinedExpression, OrderBy
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/auth/decorators.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Callable, List, Optional, Set, Union
from typing import Callable, List, Optional, Set, Union

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

def user_passes_test(
test_func: Callable, login_url: Optional[str] = ..., redirect_field_name: str = ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/auth/handlers/modwsgi.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional
from typing import Any, Dict

UserModel: Any

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import getpass as getpass
import getpass as getpass # noqa: F401
from typing import Any

from django.core.management.base import BaseCommand
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/auth/mixins.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Callable, List, Optional
from typing import Any, Callable, List

from django import http
from django.http.response import HttpResponse, HttpResponseRedirect
Expand Down
1 change: 0 additions & 1 deletion django-stubs/contrib/auth/password_validation.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pathlib import Path, PosixPath
from typing import Any, List, Mapping, Optional, Protocol, Sequence, Set, Union

from django.contrib.auth.base_user import AbstractBaseUser
from django.db.models.base import Model

_UserModel = Model
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/contenttypes/checks.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import Any, List

def check_generic_foreign_keys(app_configs: None = ..., **kwargs: Any) -> List[Any]: ...
def check_model_name_lengths(app_configs: None = ..., **kwargs: Any) -> List[Any]: ...
10 changes: 5 additions & 5 deletions django-stubs/contrib/contenttypes/fields.pyi
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union, Generic
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union

from django.contrib.contenttypes.models import ContentType
from django.core.checks.messages import Error
from django.db.models.base import Model
from django.db.models.expressions import Combinable
from django.db.models.fields.mixins import FieldCacheMixin
from django.db.models.fields.related import ForeignObject
from django.db.models.fields.related_descriptors import ReverseManyToOneDescriptor
from django.db.models.fields.reverse_related import ForeignObjectRel

from django.db.models.expressions import Combinable
from django.db.models.fields import Field, PositiveIntegerField
from django.db.models.fields.mixins import FieldCacheMixin
from django.db.models.query import QuerySet
from django.db.models.query_utils import FilteredRelation, PathInfo
from django.db.models.sql.where import WhereNode

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

class GenericForeignKey(FieldCacheMixin):
# django-stubs implementation only fields
_pyi_private_set_type: Union[Any, Combinable]
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/contenttypes/views.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional, Union
from typing import Union

from django.http.request import HttpRequest
from django.http.response import HttpResponseRedirect
Expand Down
2 changes: 0 additions & 2 deletions django-stubs/contrib/flatpages/views.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Any, Optional

from django.contrib.flatpages.models import FlatPage
from django.core.handlers.wsgi import WSGIRequest
from django.http.response import HttpResponse
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/messages/context_processors.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Union

from django.contrib.messages.storage.base import BaseStorage
from django.http.request import HttpRequest
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/messages/storage/base.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional, Union
from typing import Any, List, Optional

from django.http.request import HttpRequest
from django.http.response import HttpResponseBase
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/messages/utils.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from typing import Dict, Optional
from typing import Dict

def get_level_tags() -> Dict[int, str]: ...
2 changes: 1 addition & 1 deletion django-stubs/contrib/messages/views.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional
from typing import Dict

from django.forms.forms import BaseForm
from django.http.response import HttpResponse
Expand Down
5 changes: 3 additions & 2 deletions django-stubs/contrib/postgres/indexes.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import Any, Optional, Sequence
from typing import Optional, Sequence

from django.db.models import Index
from django.db.models.query_utils import Q

from django.db.models import Index

class PostgresIndex(Index): ...

class BrinIndex(PostgresIndex):
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/staticfiles/checks.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import Any, List

from django.core.checks.messages import Error

Expand Down
1 change: 0 additions & 1 deletion django-stubs/contrib/staticfiles/storage.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ from typing import Any, Callable, Iterator, Optional, Tuple
from django.core.files.base import File
from django.core.files.storage import FileSystemStorage
from django.utils.functional import LazyObject
from django.utils.safestring import SafeText

class StaticFilesStorage(FileSystemStorage):
base_location: Any = ...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Any

from django.template.base import Parser, Token
from django.templatetags.static import StaticNode
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/staticfiles/utils.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections import OrderedDict
from typing import Any, Iterator, List, Optional, Tuple, Union
from typing import Iterator, List, Optional, Tuple, Union

from django.core.files.storage import FileSystemStorage

Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/staticfiles/views.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Any

from django.core.handlers.wsgi import WSGIRequest
from django.http.response import FileResponse
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/syndication/views.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List

from django.core.exceptions import ObjectDoesNotExist
from django.core.handlers.wsgi import WSGIRequest
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/core/checks/caches.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import Any, List

from django.core.checks.messages import Error

Expand Down
2 changes: 1 addition & 1 deletion django-stubs/core/checks/database.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from typing import Any, List, Optional
from typing import Any, List

def check_database_backends(*args: Any, **kwargs: Any) -> List[Any]: ...
2 changes: 1 addition & 1 deletion django-stubs/core/checks/security/base.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import Any, List

from django.core.checks.messages import Warning

Expand Down
2 changes: 1 addition & 1 deletion django-stubs/core/checks/security/csrf.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import Any, List

from django.core.checks.messages import Warning

Expand Down
2 changes: 1 addition & 1 deletion django-stubs/core/checks/security/sessions.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import Any, List

from django.core.checks.messages import Warning

Expand Down
2 changes: 1 addition & 1 deletion django-stubs/core/checks/templates.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import Any, List

from django.core.checks.messages import Error

Expand Down
2 changes: 1 addition & 1 deletion django-stubs/core/checks/urls.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Callable, List, Optional, Tuple, Union
from typing import Any, Callable, List, Tuple, Union

from django.core.checks.messages import CheckMessage, Error, Warning
from django.urls.resolvers import URLPattern, URLResolver
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/core/files/uploadhandler.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ from django.utils.datastructures import MultiValueDict
class UploadFileException(Exception): ...

class StopUpload(UploadFileException):
connection_reset = ... # type: bool
def __init__(self, connection_reset: bool = False) -> None: ...
connection_reset: bool = ...
def __init__(self, connection_reset: bool = ...) -> None: ...

class SkipFile(UploadFileException): ...
class StopFutureHandlers(UploadFileException): ...
Expand Down
2 changes: 0 additions & 2 deletions django-stubs/core/management/color.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from collections import Callable

def supports_color() -> bool: ...

class Style:
Expand Down
9 changes: 1 addition & 8 deletions django-stubs/core/management/commands/makemessages.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import os
import re
from typing import Any, Pattern, Type, Optional
from typing import Any, Optional, Pattern, Type

from django.core.management.base import BaseCommand
from django.utils.functional import cached_property
from django.utils.jslex import prepare_js_for_gettext

from django.conf import settings
from django.utils.translation import templatize

plural_forms_re: Pattern = ...
STATUS_OK: int = ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/core/paginator.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, List, Optional, Union, Iterable, Sequence, Protocol, Any
from typing import Dict, List, Optional, Protocol, Sequence, Union

from django.db.models.base import Model
from django.db.models.query import QuerySet
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/core/servers/basehttp.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from typing import Any, Dict
from wsgiref import simple_server

from django.core.handlers.wsgi import WSGIRequest, WSGIHandler
from django.core.wsgi import get_wsgi_application as get_wsgi_application
from django.core.wsgi import get_wsgi_application as get_wsgi_application # noqa: F401

class WSGIServer(simple_server.WSGIServer):
request_queue_size: int = ...
Expand Down
6 changes: 2 additions & 4 deletions django-stubs/core/signing.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from datetime import datetime, timedelta
from typing import Any, Dict, List, Optional, Type, Union, Protocol

from django.contrib.sessions.serializers import PickleSerializer
from datetime import timedelta
from typing import Any, Dict, Optional, Protocol, Type, Union

class BadSignature(Exception): ...
class SignatureExpired(BadSignature): ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/core/validators.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from typing import Any, Dict, List, Optional, Union, Pattern, Collection
from uuid import UUID

from django.core.files.base import File
from django.core.exceptions import ValidationError as ValidationError
from django.core.exceptions import ValidationError as ValidationError # noqa: F401

EMPTY_VALUES: Any

Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/backends/base/client.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Any

from django.db.backends.base.base import BaseDatabaseWrapper

Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/backends/base/features.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Any

from django.db.backends.base.base import BaseDatabaseWrapper

Expand Down
7 changes: 4 additions & 3 deletions django-stubs/db/backends/base/operations.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from datetime import date, datetime, timedelta
from decimal import Decimal
from typing import Any, List, Optional, Set, Tuple, Type, Union, Sequence
from typing import Any, List, Optional, Sequence, Tuple, Type, Union

from django.core.management.color import Style
from django.db import DefaultConnectionProxy
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.backends.sqlite3.base import DatabaseWrapper
from django.db.backends.utils import CursorWrapper
from django.db.models.base import Model
from django.db.models.expressions import Case, Expression
from django.db.models.fields import Field
from django.db.models.sql.compiler import SQLCompiler

from django.db import DefaultConnectionProxy
from django.db.models.fields import Field

class BaseDatabaseOperations:
compiler_module: str = ...
integer_field_ranges: Any = ...
Expand Down
3 changes: 2 additions & 1 deletion django-stubs/db/backends/base/validation.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, List, Optional
from typing import Any, List

from django.db.backends.base.base import BaseDatabaseWrapper

from django.db.models.fields import Field

class BaseDatabaseValidation:
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/backends/mysql/client.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Union
from typing import Dict, List, Optional, Union

from django.db.backends.base.client import BaseDatabaseClient

Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/backends/postgresql/client.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional
from typing import Dict

from django.db.backends.base.client import BaseDatabaseClient

Expand Down
3 changes: 1 addition & 2 deletions django-stubs/db/backends/sqlite3/base.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from sqlite3 import dbapi2 as Database
from sqlite3 import dbapi2 as Database
from typing import Any, Callable, Iterator
from typing import Any, Callable

from django.db.backends.base.base import BaseDatabaseWrapper

Expand Down
Loading

0 comments on commit 963d50c

Please sign in to comment.