add linting stubs with flake8-pyi and check for unused imports (#186)

This commit is contained in:
Maxim Kurnikov
2019-09-25 02:20:23 +03:00
committed by GitHub
parent 7407b93151
commit 963d50c717
91 changed files with 139 additions and 176 deletions

View File

@@ -28,6 +28,10 @@ jobs:
python: 3.7 python: 3.7
script: 'flake8' 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 - name: Lint plugin code with isort
python: 3.7 python: 3.7
script: 'isort --check --diff' script: 'isort --check --diff'

View File

@@ -1,6 +1,7 @@
black black
pytest-mypy-plugins==1.0.3 pytest-mypy-plugins==1.0.3
psycopg2 psycopg2
flake8 flake8==3.7.8
flake8-pyi==19.3.0
isort==4.3.21 isort==4.3.21
-e . -e .

View File

@@ -1,6 +1,6 @@
import threading import threading
from collections import OrderedDict 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.migrations.state import AppConfigStub
from django.db.models.base import Model from django.db.models.base import Model
@@ -8,8 +8,8 @@ from django.db.models.base import Model
from .config import AppConfig from .config import AppConfig
class Apps: class Apps:
all_models: "Dict[str, OrderedDict[str, Type[Model]]]" = ... all_models: Dict[str, OrderedDict[str, Type[Model]]] = ...
app_configs: "OrderedDict[str, AppConfig]" = ... app_configs: OrderedDict[str, AppConfig] = ...
stored_app_configs: List[Any] = ... stored_app_configs: List[Any] = ...
apps_ready: bool = ... apps_ready: bool = ...
ready_event: threading.Event = ... ready_event: threading.Event = ...

View File

@@ -1,6 +1,6 @@
from typing import Any, List, Union 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 from django.core.checks.messages import Error
_CheckError = Union[str, Error] _CheckError = Union[str, Error]

View File

@@ -1,7 +1,6 @@
from typing import Any, Optional from typing import Any
from django.contrib.admin.helpers import InlineAdminForm 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.base import Parser, Token
from django.template.context import Context, RequestContext from django.template.context import Context, RequestContext

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional from typing import Any
register: Any register: Any

View File

@@ -2,7 +2,11 @@ from collections import OrderedDict
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
from django.contrib.admin.filters import ListFilter, SimpleListFilter 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.core.handlers.wsgi import WSGIRequest
from django.db.models.base import Model from django.db.models.base import Model
from django.db.models.expressions import Combinable, CombinedExpression, OrderBy from django.db.models.expressions import Combinable, CombinedExpression, OrderBy

View File

@@ -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( def user_passes_test(
test_func: Callable, login_url: Optional[str] = ..., redirect_field_name: str = ... test_func: Callable, login_url: Optional[str] = ..., redirect_field_name: str = ...

View File

@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional from typing import Any, Dict
UserModel: Any UserModel: Any

View File

@@ -1,4 +1,4 @@
import getpass as getpass import getpass as getpass # noqa: F401
from typing import Any from typing import Any
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand

View File

@@ -1,4 +1,4 @@
from typing import Any, Callable, List, Optional from typing import Any, Callable, List
from django import http from django import http
from django.http.response import HttpResponse, HttpResponseRedirect from django.http.response import HttpResponse, HttpResponseRedirect

View File

@@ -1,7 +1,6 @@
from pathlib import Path, PosixPath from pathlib import Path, PosixPath
from typing import Any, List, Mapping, Optional, Protocol, Sequence, Set, Union 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 from django.db.models.base import Model
_UserModel = Model _UserModel = Model

View File

@@ -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_generic_foreign_keys(app_configs: None = ..., **kwargs: Any) -> List[Any]: ...
def check_model_name_lengths(app_configs: None = ..., **kwargs: Any) -> List[Any]: ... def check_model_name_lengths(app_configs: None = ..., **kwargs: Any) -> List[Any]: ...

View File

@@ -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.contrib.contenttypes.models import ContentType
from django.core.checks.messages import Error from django.core.checks.messages import Error
from django.db.models.base import Model 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 import ForeignObject
from django.db.models.fields.related_descriptors import ReverseManyToOneDescriptor from django.db.models.fields.related_descriptors import ReverseManyToOneDescriptor
from django.db.models.fields.reverse_related import ForeignObjectRel 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 import QuerySet
from django.db.models.query_utils import FilteredRelation, PathInfo from django.db.models.query_utils import FilteredRelation, PathInfo
from django.db.models.sql.where import WhereNode from django.db.models.sql.where import WhereNode
from django.db.models.fields import Field, PositiveIntegerField
class GenericForeignKey(FieldCacheMixin): class GenericForeignKey(FieldCacheMixin):
# django-stubs implementation only fields # django-stubs implementation only fields
_pyi_private_set_type: Union[Any, Combinable] _pyi_private_set_type: Union[Any, Combinable]

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional, Union from typing import Union
from django.http.request import HttpRequest from django.http.request import HttpRequest
from django.http.response import HttpResponseRedirect from django.http.response import HttpResponseRedirect

View File

@@ -1,5 +1,3 @@
from typing import Any, Optional
from django.contrib.flatpages.models import FlatPage from django.contrib.flatpages.models import FlatPage
from django.core.handlers.wsgi import WSGIRequest from django.core.handlers.wsgi import WSGIRequest
from django.http.response import HttpResponse from django.http.response import HttpResponse

View File

@@ -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.contrib.messages.storage.base import BaseStorage
from django.http.request import HttpRequest from django.http.request import HttpRequest

View File

@@ -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.request import HttpRequest
from django.http.response import HttpResponseBase from django.http.response import HttpResponseBase

View File

@@ -1,3 +1,3 @@
from typing import Dict, Optional from typing import Dict
def get_level_tags() -> Dict[int, str]: ... def get_level_tags() -> Dict[int, str]: ...

View File

@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional from typing import Dict
from django.forms.forms import BaseForm from django.forms.forms import BaseForm
from django.http.response import HttpResponse from django.http.response import HttpResponse

View File

@@ -1,7 +1,8 @@
from typing import Any, Optional, Sequence from typing import Optional, Sequence
from django.db.models.query_utils import Q
from django.db.models import Index from django.db.models import Index
from django.db.models.query_utils import Q
class PostgresIndex(Index): ... class PostgresIndex(Index): ...

View File

@@ -1,4 +1,4 @@
from typing import Any, List, Optional from typing import Any, List
from django.core.checks.messages import Error from django.core.checks.messages import Error

View File

@@ -4,7 +4,6 @@ from typing import Any, Callable, Iterator, Optional, Tuple
from django.core.files.base import File from django.core.files.base import File
from django.core.files.storage import FileSystemStorage from django.core.files.storage import FileSystemStorage
from django.utils.functional import LazyObject from django.utils.functional import LazyObject
from django.utils.safestring import SafeText
class StaticFilesStorage(FileSystemStorage): class StaticFilesStorage(FileSystemStorage):
base_location: Any = ... base_location: Any = ...

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional from typing import Any
from django.template.base import Parser, Token from django.template.base import Parser, Token
from django.templatetags.static import StaticNode from django.templatetags.static import StaticNode

View File

@@ -1,5 +1,5 @@
from collections import OrderedDict 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 from django.core.files.storage import FileSystemStorage

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional from typing import Any
from django.core.handlers.wsgi import WSGIRequest from django.core.handlers.wsgi import WSGIRequest
from django.http.response import FileResponse from django.http.response import FileResponse

View File

@@ -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.exceptions import ObjectDoesNotExist
from django.core.handlers.wsgi import WSGIRequest from django.core.handlers.wsgi import WSGIRequest

View File

@@ -1,4 +1,4 @@
from typing import Any, List, Optional from typing import Any, List
from django.core.checks.messages import Error from django.core.checks.messages import Error

View File

@@ -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]: ... def check_database_backends(*args: Any, **kwargs: Any) -> List[Any]: ...

View File

@@ -1,4 +1,4 @@
from typing import Any, List, Optional from typing import Any, List
from django.core.checks.messages import Warning from django.core.checks.messages import Warning

View File

@@ -1,4 +1,4 @@
from typing import Any, List, Optional from typing import Any, List
from django.core.checks.messages import Warning from django.core.checks.messages import Warning

View File

@@ -1,4 +1,4 @@
from typing import Any, List, Optional from typing import Any, List
from django.core.checks.messages import Warning from django.core.checks.messages import Warning

View File

@@ -1,4 +1,4 @@
from typing import Any, List, Optional from typing import Any, List
from django.core.checks.messages import Error from django.core.checks.messages import Error

View File

@@ -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.core.checks.messages import CheckMessage, Error, Warning
from django.urls.resolvers import URLPattern, URLResolver from django.urls.resolvers import URLPattern, URLResolver

View File

@@ -8,8 +8,8 @@ from django.utils.datastructures import MultiValueDict
class UploadFileException(Exception): ... class UploadFileException(Exception): ...
class StopUpload(UploadFileException): class StopUpload(UploadFileException):
connection_reset = ... # type: bool connection_reset: bool = ...
def __init__(self, connection_reset: bool = False) -> None: ... def __init__(self, connection_reset: bool = ...) -> None: ...
class SkipFile(UploadFileException): ... class SkipFile(UploadFileException): ...
class StopFutureHandlers(UploadFileException): ... class StopFutureHandlers(UploadFileException): ...

View File

@@ -1,5 +1,3 @@
from collections import Callable
def supports_color() -> bool: ... def supports_color() -> bool: ...
class Style: class Style:

View File

@@ -1,13 +1,6 @@
import os from typing import Any, Optional, Pattern, Type
import re
from typing import Any, Pattern, Type, Optional
from django.core.management.base import BaseCommand 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 = ... plural_forms_re: Pattern = ...
STATUS_OK: int = ... STATUS_OK: int = ...

View File

@@ -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.base import Model
from django.db.models.query import QuerySet from django.db.models.query import QuerySet

View File

@@ -4,7 +4,7 @@ from typing import Any, Dict
from wsgiref import simple_server from wsgiref import simple_server
from django.core.handlers.wsgi import WSGIRequest, WSGIHandler 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): class WSGIServer(simple_server.WSGIServer):
request_queue_size: int = ... request_queue_size: int = ...

View File

@@ -1,7 +1,5 @@
from datetime import datetime, timedelta from datetime import timedelta
from typing import Any, Dict, List, Optional, Type, Union, Protocol from typing import Any, Dict, Optional, Protocol, Type, Union
from django.contrib.sessions.serializers import PickleSerializer
class BadSignature(Exception): ... class BadSignature(Exception): ...
class SignatureExpired(BadSignature): ... class SignatureExpired(BadSignature): ...

View File

@@ -5,7 +5,7 @@ from typing import Any, Dict, List, Optional, Union, Pattern, Collection
from uuid import UUID from uuid import UUID
from django.core.files.base import File 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 EMPTY_VALUES: Any

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional from typing import Any
from django.db.backends.base.base import BaseDatabaseWrapper from django.db.backends.base.base import BaseDatabaseWrapper

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional from typing import Any
from django.db.backends.base.base import BaseDatabaseWrapper from django.db.backends.base.base import BaseDatabaseWrapper

View File

@@ -1,17 +1,18 @@
from datetime import date, datetime, timedelta from datetime import date, datetime, timedelta
from decimal import Decimal 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.core.management.color import Style
from django.db import DefaultConnectionProxy
from django.db.backends.base.base import BaseDatabaseWrapper from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.backends.sqlite3.base import DatabaseWrapper from django.db.backends.sqlite3.base import DatabaseWrapper
from django.db.backends.utils import CursorWrapper from django.db.backends.utils import CursorWrapper
from django.db.models.base import Model from django.db.models.base import Model
from django.db.models.expressions import Case, Expression 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.models.sql.compiler import SQLCompiler
from django.db import DefaultConnectionProxy
from django.db.models.fields import Field
class BaseDatabaseOperations: class BaseDatabaseOperations:
compiler_module: str = ... compiler_module: str = ...
integer_field_ranges: Any = ... integer_field_ranges: Any = ...

View File

@@ -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.backends.base.base import BaseDatabaseWrapper
from django.db.models.fields import Field from django.db.models.fields import Field
class BaseDatabaseValidation: class BaseDatabaseValidation:

View File

@@ -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 from django.db.backends.base.client import BaseDatabaseClient

View File

@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional from typing import Dict
from django.db.backends.base.client import BaseDatabaseClient from django.db.backends.base.client import BaseDatabaseClient

View File

@@ -1,6 +1,5 @@
from sqlite3 import dbapi2 as Database from sqlite3 import dbapi2 as Database
from sqlite3 import dbapi2 as Database from typing import Any, Callable
from typing import Any, Callable, Iterator
from django.db.backends.base.base import BaseDatabaseWrapper from django.db.backends.base.base import BaseDatabaseWrapper

View File

@@ -1,7 +1,7 @@
import types import types
from datetime import date, datetime, time from datetime import date, datetime, time
from decimal import Decimal from decimal import Decimal
from typing import Any, Dict, Iterator, List, Mapping, Optional, Sequence, Tuple, Union, Type from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Type, Union
from uuid import UUID from uuid import UUID
logger: Any logger: Any

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional, Tuple from typing import Optional, Tuple
from django.db.migrations.migration import Migration from django.db.migrations.migration import Migration
from django.db.utils import DatabaseError from django.db.utils import DatabaseError

View File

@@ -1,4 +1,4 @@
from typing import Any, Callable, List, Optional, Tuple, Union, Set, Dict from typing import Any, Dict, List, Optional, Set, Tuple, Union
from django.db.migrations.migration import Migration, SwappableTuple from django.db.migrations.migration import Migration, SwappableTuple
from django.db.migrations.state import ProjectState from django.db.migrations.state import ProjectState

View File

@@ -1,4 +1,4 @@
from typing import Any, Tuple, Type, List from typing import Any, List, Tuple
from django.db.backends.base.schema import BaseDatabaseSchemaEditor from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import ProjectState from django.db.migrations.state import ProjectState

View File

@@ -1,4 +1,4 @@
from typing import Any, Iterable, Union, Optional, List from typing import Any
COMPILED_REGEX_TYPE: Any COMPILED_REGEX_TYPE: Any

View File

@@ -1,9 +1,7 @@
from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, TypeVar, Union, ClassVar, Type from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, TypeVar, Union
from django.db.models.manager import Manager
from django.core.checks.messages import CheckMessage from django.core.checks.messages import CheckMessage
from django.db.models.manager import Manager
from django.db.models.options import Options from django.db.models.options import Options
_Self = TypeVar("_Self", bound="Model") _Self = TypeVar("_Self", bound="Model")

View File

@@ -1,4 +1,4 @@
from typing import Any, Callable, List, Optional, Type, Union, Tuple, Iterable, overload, TypeVar from typing import Any, Callable, Iterable, List, Optional, Tuple, Type, TypeVar, Union, overload
from django.core.files.base import File from django.core.files.base import File
from django.core.files.images import ImageFile from django.core.files.images import ImageFile
@@ -6,7 +6,6 @@ from django.core.files.storage import FileSystemStorage, Storage
from django.db.models.base import Model from django.db.models.base import Model
from django.db.models.fields import Field, _FieldChoices, _ValidatorCallable, _ErrorMessagesToOverride from django.db.models.fields import Field, _FieldChoices, _ValidatorCallable, _ErrorMessagesToOverride
from django.forms import fields as form_fields
BLANK_CHOICE_DASH: List[Tuple[str, str]] = ... BLANK_CHOICE_DASH: List[Tuple[str, str]] = ...

View File

@@ -1,43 +1,27 @@
from typing import ( from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple, Type, TypeVar, Union, overload
Any,
Callable,
Dict,
Iterable,
List,
Optional,
Sequence,
TYPE_CHECKING,
Tuple,
Type,
TypeVar,
Union,
overload,
)
from uuid import UUID from uuid import UUID
from django.db import models
from django.db.models.base import Model
from django.db.models.fields import Field
from django.db.models.query_utils import Q, PathInfo
from django.db.models.manager import RelatedManager
from django.db.models.expressions import Combinable from django.db.models.expressions import Combinable
from django.db.models.fields.mixins import FieldCacheMixin from django.db.models.fields.mixins import FieldCacheMixin
from django.db.models.query_utils import PathInfo, Q from django.db.models.fields.related_descriptors import ( # noqa: F401
from django.db import models
from django.db.models import Field, Model
from django.db.models.fields.related_descriptors import (
ForwardOneToOneDescriptor as ForwardOneToOneDescriptor, ForwardOneToOneDescriptor as ForwardOneToOneDescriptor,
ForwardManyToOneDescriptor as ForwardManyToOneDescriptor, ForwardManyToOneDescriptor as ForwardManyToOneDescriptor,
ManyToManyDescriptor as ManyToManyDescriptor, ManyToManyDescriptor as ManyToManyDescriptor,
ReverseOneToOneDescriptor as ReverseOneToOneDescriptor, ReverseOneToOneDescriptor as ReverseOneToOneDescriptor,
ReverseManyToOneDescriptor as ReverseManyToOneDescriptor, ReverseManyToOneDescriptor as ReverseManyToOneDescriptor,
) )
from django.db.models.fields.reverse_related import ( from django.db.models.fields.reverse_related import ( # noqa: F401
ForeignObjectRel as ForeignObjectRel, ForeignObjectRel as ForeignObjectRel,
OneToOneRel as OneToOneRel, OneToOneRel as OneToOneRel,
ManyToOneRel as ManyToOneRel, ManyToOneRel as ManyToOneRel,
ManyToManyRel as ManyToManyRel, ManyToManyRel as ManyToManyRel,
) )
if TYPE_CHECKING:
from django.db.models.manager import RelatedManager
_T = TypeVar("_T", bound=models.Model) _T = TypeVar("_T", bound=models.Model)
_F = TypeVar("_F", bound=models.Field) _F = TypeVar("_F", bound=models.Field)
_Choice = Tuple[Any, str] _Choice = Tuple[Any, str]

View File

@@ -1,12 +1,12 @@
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
from django.db.models.base import Model from django.db.models.base import Model
from django.db.models.fields import AutoField, Field
from django.db.models.fields.related import ForeignKey, OneToOneField, RelatedField from django.db.models.fields.related import ForeignKey, OneToOneField, RelatedField
from django.db.models.lookups import BuiltinLookup, StartsWith from django.db.models.lookups import BuiltinLookup, StartsWith
from django.db.models.query_utils import FilteredRelation, PathInfo, Q from django.db.models.query_utils import FilteredRelation, PathInfo
from django.db.models.sql.where import WhereNode from django.db.models.sql.where import WhereNode
from django.db.models.fields import AutoField, Field
from .mixins import FieldCacheMixin from .mixins import FieldCacheMixin
class ForeignObjectRel(FieldCacheMixin): class ForeignObjectRel(FieldCacheMixin):

View File

@@ -1,12 +1,10 @@
from collections import OrderedDict
from datetime import datetime from datetime import datetime
from typing import Any, Dict, Iterable, List, Optional, Tuple, Type, Union, Mapping from typing import Any, Iterable, List, Mapping, Optional, Tuple, Type, Union
from django.db.backends.sqlite3.base import DatabaseWrapper from django.db.backends.sqlite3.base import DatabaseWrapper
from django.db.models.expressions import Combinable, Expression, Func from django.db.models.expressions import Expression, Func
from django.db.models.query_utils import RegisterLookupMixin from django.db.models.query_utils import RegisterLookupMixin
from django.db.models.sql.compiler import SQLCompiler from django.db.models.sql.compiler import SQLCompiler
from django.db.models.sql.query import Query
from django.utils.datastructures import OrderedSet from django.utils.datastructures import OrderedSet
from django.utils.safestring import SafeText from django.utils.safestring import SafeText

View File

@@ -1,5 +1,5 @@
import collections import collections
from typing import Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, Type, Union, TypeVar, Generic, Sequence from typing import Any, Callable, Dict, Generic, Iterator, List, Optional, Sequence, Set, Tuple, Type, TypeVar, Union
from django.apps.config import AppConfig from django.apps.config import AppConfig
from django.apps.registry import Apps from django.apps.registry import Apps
@@ -9,13 +9,13 @@ from django.contrib.postgres.fields.citext import CIText
from django.db.backends.sqlite3.base import DatabaseWrapper from django.db.backends.sqlite3.base import DatabaseWrapper
from django.db.models.base import Model from django.db.models.base import Model
from django.db.models.fields.mixins import FieldCacheMixin from django.db.models.fields.mixins import FieldCacheMixin
from django.db.models.fields.related import OneToOneField, ManyToManyField from django.db.models.fields.related import ManyToManyField, OneToOneField
from django.db.models.fields.reverse_related import ForeignObjectRel from django.db.models.fields.reverse_related import ForeignObjectRel
from django.db.models.manager import Manager from django.db.models.manager import Manager
from django.db.models.query_utils import PathInfo from django.db.models.query_utils import PathInfo
from django.utils.datastructures import ImmutableList from django.utils.datastructures import ImmutableList
from django.db.models.fields import Field, mixins, AutoField from django.db.models.fields import AutoField, Field
PROXY_PARENTS: Any PROXY_PARENTS: Any
EMPTY_RELATION_TREE: Any EMPTY_RELATION_TREE: Any

View File

@@ -1,7 +1,9 @@
import datetime import datetime
from typing import ( from typing import (
Any, Any,
Collection,
Dict, Dict,
Generic,
Iterable, Iterable,
Iterator, Iterator,
List, List,
@@ -14,18 +16,15 @@ from typing import (
TypeVar, TypeVar,
Union, Union,
overload, overload,
Generic,
NamedTuple,
Collection,
) )
from django.db.models.base import Model from django.db.models.base import Model
from django.db.models.expressions import Combinable as Combinable, F as F from django.db.models.expressions import Combinable as Combinable, F as F # noqa: F401
from django.db.models.sql.query import Query, RawQuery from django.db.models.sql.query import Query, RawQuery
from django.db import models from django.db import models
from django.db.models import Manager from django.db.models import Manager
from django.db.models.query_utils import Q as Q from django.db.models.query_utils import Q as Q # noqa: F401
_T = TypeVar("_T", bound=models.Model, covariant=True) _T = TypeVar("_T", bound=models.Model, covariant=True)
_QS = TypeVar("_QS", bound="_BaseQuerySet") _QS = TypeVar("_QS", bound="_BaseQuerySet")
@@ -43,8 +42,7 @@ class _BaseQuerySet(Generic[_T], Sized):
def as_manager(cls) -> Manager[Any]: ... def as_manager(cls) -> Manager[Any]: ...
def __len__(self) -> int: ... def __len__(self) -> int: ...
def __bool__(self) -> bool: ... def __bool__(self) -> bool: ...
def __class_getitem__(cls, item: Type[_T]): def __class_getitem__(cls, item: Type[_T]): ...
pass
def __getstate__(self) -> Dict[str, Any]: ... def __getstate__(self) -> Dict[str, Any]: ...
# Technically, the other QuerySet must be of the same type _T, but _T is covariant # Technically, the other QuerySet must be of the same type _T, but _T is covariant
def __and__(self: _QS, other: _BaseQuerySet[_T]) -> _QS: ... def __and__(self: _QS, other: _BaseQuerySet[_T]) -> _QS: ...

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional, Tuple, Type, Union from typing import Tuple, Type, Union
from django.db.models.base import Model from django.db.models.base import Model

View File

@@ -38,5 +38,5 @@ def atomic(using: _C) -> _C: ...
# Decorator or context-manager with parameters # Decorator or context-manager with parameters
@overload @overload
def atomic(using: Optional[str] = ..., savepoint: bool = True) -> Atomic: ... def atomic(using: Optional[str] = ..., savepoint: bool = ...) -> Atomic: ...
def non_atomic_requests(using: Callable = ...) -> Callable: ... def non_atomic_requests(using: Callable = ...) -> Callable: ...

View File

@@ -1,7 +1,4 @@
from typing import Any, Callable, List, Optional, Tuple, Type, Union from typing import Any, Callable, List, Optional, Tuple, Union
from django.apps.config import AppConfig
from django.db.models.base import Model
NONE_ID: Any NONE_ID: Any
NO_RECEIVERS: Any NO_RECEIVERS: Any

View File

@@ -1,6 +1,5 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from decimal import Decimal from typing import Any, Callable, Iterable, List, Optional, Pattern, Sequence, Tuple, Type, Union
from typing import Any, Callable, List, Optional, Pattern, Sequence, Type, Union, Tuple, Iterable
from django.core.validators import BaseValidator from django.core.validators import BaseValidator
from django.forms.boundfield import BoundField from django.forms.boundfield import BoundField

View File

@@ -1,4 +1,4 @@
from typing import Any, Dict, Iterator, List, Mapping, Optional, Sequence, Type, Union, Tuple from typing import Any, Dict, Iterator, List, Mapping, Optional, Sequence, Type, Union
from django.core.exceptions import ValidationError as ValidationError from django.core.exceptions import ValidationError as ValidationError
from django.forms.boundfield import BoundField from django.forms.boundfield import BoundField

View File

@@ -1,7 +1,6 @@
from typing import Any, Dict from typing import Any, Dict
from django.template.backends.base import BaseEngine from django.template.backends.base import BaseEngine
from django.template.engine import Engine
from django.template import Template from django.template import Template

View File

@@ -10,17 +10,16 @@ from typing import (
Pattern, Pattern,
Set, Set,
Tuple, Tuple,
Type,
TypeVar,
Union, Union,
overload, overload,
TypeVar,
Type,
) )
from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.sessions.backends.base import SessionBase from django.contrib.sessions.backends.base import SessionBase
from django.db.models.base import Model
from django.utils.datastructures import CaseInsensitiveMapping, ImmutableList, MultiValueDict from django.utils.datastructures import CaseInsensitiveMapping, ImmutableList, MultiValueDict
from django.contrib.auth.base_user import AbstractBaseUser
from django.core.files import uploadedfile, uploadhandler from django.core.files import uploadedfile, uploadhandler
from django.urls import ResolverMatch from django.urls import ResolverMatch

View File

@@ -48,8 +48,8 @@ class HttpResponseBase(Iterable[Any]):
samesite: str = ..., samesite: str = ...,
) -> None: ... ) -> None: ...
def setdefault(self, key: str, value: str) -> None: ... def setdefault(self, key: str, value: str) -> None: ...
def set_signed_cookie(self, key: str, value: str, salt: str = "", **kwargs: Any) -> None: ... def set_signed_cookie(self, key: str, value: str, salt: str = ..., **kwargs: Any) -> None: ...
def delete_cookie(self, key: str, path: str = "", domain: Optional[str] = ...) -> None: ... def delete_cookie(self, key: str, path: str = ..., domain: Optional[str] = ...) -> None: ...
def make_bytes(self, value: object) -> bytes: ... def make_bytes(self, value: object) -> bytes: ...
def close(self) -> None: ... def close(self) -> None: ...
def write(self, content: Union[str, bytes]) -> None: ... def write(self, content: Union[str, bytes]) -> None: ...

View File

@@ -22,8 +22,7 @@ def render(
using: Optional[str] = ..., using: Optional[str] = ...,
) -> HttpResponse: ... ) -> HttpResponse: ...
class SupportsGetAbsoluteUrl(Protocol): class SupportsGetAbsoluteUrl(Protocol): ...
pass
def redirect( def redirect(
to: Union[Callable, str, SupportsGetAbsoluteUrl], *args: Any, permanent: bool = ..., **kwargs: Any to: Union[Callable, str, SupportsGetAbsoluteUrl], *args: Any, permanent: bool = ..., **kwargs: Any

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional from typing import Any
from django.http.request import HttpRequest from django.http.request import HttpRequest
from django.utils.safestring import SafeText from django.utils.safestring import SafeText

View File

@@ -2,7 +2,7 @@ from datetime import date as _date, datetime, time as _time
from typing import Any, Callable, Dict, List, Optional, Union from typing import Any, Callable, Dict, List, Optional, Union
from django.utils.safestring import SafeText from django.utils.safestring import SafeText
from django.utils.html import escape as escape from django.utils.html import escape as escape # noqa: F401
register: Any register: Any

View File

@@ -1,8 +1,8 @@
from typing import Any, Dict, List, Optional, Union from typing import Any, Dict, List, Optional, Union
from . import engines as engines from . import engines as engines # noqa: F401
from django.http.request import HttpRequest from django.http.request import HttpRequest
from django.template.exceptions import TemplateDoesNotExist as TemplateDoesNotExist from django.template.exceptions import TemplateDoesNotExist as TemplateDoesNotExist # noqa: F401
def get_template(template_name: str, using: Optional[str] = ...) -> Any: ... def get_template(template_name: str, using: Optional[str] = ...) -> Any: ...
def select_template(template_name_list: Union[List[str], str], using: Optional[str] = ...) -> Any: ... def select_template(template_name_list: Union[List[str], str], using: Optional[str] = ...) -> Any: ...

View File

@@ -7,7 +7,6 @@ from django.http.request import HttpRequest
from django.template.base import Template from django.template.base import Template
from django.template.context import RequestContext from django.template.context import RequestContext
from django.test.client import Client from django.test.client import Client
from django.utils.functional import SimpleLazyObject
from django.http import HttpResponse from django.http import HttpResponse

View File

@@ -1,8 +1,8 @@
import logging import logging
from argparse import ArgumentParser from argparse import ArgumentParser
from io import StringIO from io import StringIO
from typing import Any, Dict, List, Optional, Set, Tuple, Type, Union, Sequence from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, Type
from unittest import TestCase, TextTestResult, TestSuite from unittest import TestCase, TestSuite, TextTestResult
from django.db.backends.base.base import BaseDatabaseWrapper from django.db.backends.base.base import BaseDatabaseWrapper
from django.test.testcases import SimpleTestCase, TestCase from django.test.testcases import SimpleTestCase, TestCase

View File

@@ -1,5 +1,5 @@
from typing import Any from typing import Any
from django.core.signals import setting_changed as setting_changed from django.core.signals import setting_changed as setting_changed # noqa: F401
template_rendered: Any template_rendered: Any
COMPLEX_OVERRIDE_SETTINGS: Any COMPLEX_OVERRIDE_SETTINGS: Any

View File

@@ -15,7 +15,7 @@ from django.template.base import Template
from django.test.client import Client from django.test.client import Client
from django.test.utils import CaptureQueriesContext, ContextList from django.test.utils import CaptureQueriesContext, ContextList
from django.utils.safestring import SafeText from django.utils.safestring import SafeText
from django.db import connections as connections from django.db import connections as connections # noqa: F401
class _AssertNumQueriesContext(CaptureQueriesContext): class _AssertNumQueriesContext(CaptureQueriesContext):
test_case: SimpleTestCase = ... test_case: SimpleTestCase = ...

View File

@@ -1,4 +1,4 @@
from typing import Any, Dict, Type, Union, Protocol from typing import Any, Dict, Type, Union
from uuid import UUID from uuid import UUID
class IntConverter: class IntConverter:

View File

@@ -1,7 +1,4 @@
from django.http import Http404 from django.http import Http404
class Resolver404(Http404): class Resolver404(Http404): ...
pass class NoReverseMatch(Exception): ...
class NoReverseMatch(Exception):
pass

View File

@@ -1,5 +1,5 @@
from os.path import abspath from os.path import abspath
from typing import Any, Optional, Union from typing import Any, Union
abspathu = abspath abspathu = abspath

View File

@@ -1,5 +1,5 @@
from hmac import HMAC from hmac import HMAC
from typing import Any, Callable, Optional, Union from typing import Callable, Optional, Union
using_sysrandom: bool using_sysrandom: bool

View File

@@ -71,5 +71,4 @@ class CaseInsensitiveMapping(Mapping):
def __getitem__(self, key: str) -> Any: ... def __getitem__(self, key: str) -> Any: ...
def __len__(self) -> int: ... def __len__(self) -> int: ...
def __iter__(self) -> Iterator[str]: ... def __iter__(self) -> Iterator[str]: ...
def copy(self: _T) -> _T: def copy(self: _T) -> _T: ...
return self

View File

@@ -1,5 +1,4 @@
from datetime import timedelta from datetime import timedelta
from typing import Any, Optional
def duration_string(duration: timedelta) -> str: ... def duration_string(duration: timedelta) -> str: ...
def duration_iso_string(duration: timedelta) -> str: ... def duration_iso_string(duration: timedelta) -> str: ...

View File

@@ -1,5 +1,5 @@
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
from functools import wraps as wraps from functools import wraps as wraps # noqa: F401
from django.db.models.base import Model from django.db.models.base import Model

View File

@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Set, Tuple, Union, Iterable from typing import Any, Iterable, List, Optional, Tuple, Union
ETAG_MATCH: Any ETAG_MATCH: Any
MONTHS: Any MONTHS: Any

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional from typing import Any
def clean_ipv6_address(ip_str: Any, unpack_ipv4: bool = ..., error_message: Any = ...): ... def clean_ipv6_address(ip_str: Any, unpack_ipv4: bool = ..., error_message: Any = ...): ...
def is_valid_ipv6_address(ip_str: str) -> bool: ... def is_valid_ipv6_address(ip_str: str) -> bool: ...

View File

@@ -1,4 +1,4 @@
from typing import Any, List, Optional from typing import Any, List
COMMON_P: str COMMON_P: str
WORDS: Any WORDS: Any

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional from typing import Any
def import_string(dotted_path: str) -> Any: ... def import_string(dotted_path: str) -> Any: ...
def autodiscover_modules(*args: Any, **kwargs: Any) -> None: ... def autodiscover_modules(*args: Any, **kwargs: Any) -> None: ...

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional from typing import Any
dot_re: Any dot_re: Any

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional from typing import Any
def gettext(message: Any): ... def gettext(message: Any): ...

12
flake8-pyi.ini Normal file
View File

@@ -0,0 +1,12 @@
[flake8]
filename =
*.pyi
exclude =
django-sources
test-data
mypy_django_plugin
scripts
select = F401, Y
max_line_length = 120
per-file-ignores =
*__init__.pyi: F401

View File

@@ -14,14 +14,6 @@ exclude =
django-stubs django-stubs
test-data test-data
max_line_length = 120 max_line_length = 120
per-file-ignores =
# E301: expected 1 blank line
# E302: expected 2 blank lines
# E305: expected 2 blank lines after class or function definition
# E701: multiple statements on one line (colon)
# E743: ambiguous function definition 'X'
# F821: undefined name 'X'
*.pyi: E301, E302, E305, E701, E743, F821
[metadata] [metadata]
license_file = LICENSE.txt license_file = LICENSE.txt