34 Commits

Author SHA1 Message Date
Maxim Kurnikov
dceb075152 fix annotation for BaseCommand.handle() (#201) 2019-10-05 21:36:41 +03:00
Maxim Kurnikov
7e3f4bfa02 Fix ForeignKey type for self-reference defined in the abstract model (#200) 2019-10-05 21:36:29 +03:00
Maxim Kurnikov
db9ff6aaf6 Fix crash if model from same app referenced in RelatedField cannot be resolved (#199)
* do not crash if model from same app refd in ForeignKey cannot be resolved

* bump to 1.2.0
2019-10-05 20:00:51 +03:00
Maxim Kurnikov
717be5940f Reorganize code a bit, add current directory to sys.path (#198)
* reorganize code a bit

* add current directory to sys.path

* remove PYTHONPATH mention from the docs

* linting
2019-10-05 19:44:29 +03:00
Nikita Sobolev
b939bc96b7 Improves README with new example repo, python version matrix (#195) 2019-10-01 15:24:48 +03:00
Maxim Kurnikov
02bdf5be95 add support for typechecking of filter/get/exclude arguments (#183)
* add support for typechecking of filter/get/exclude arguments

* linting
2019-09-30 03:05:40 +03:00
Maxim Kurnikov
4d4b0003bd Fix Paginator properties mistyped as Callables (#193)
Co-authored-by: Nick Sweeting <git@sweeting.me>
2019-09-28 22:16:20 +03:00
Maxim Kurnikov
e143ba568c add mypy compatibility table (#190)
* add mypy compatibility table

* add django versions to compatibility table
2019-09-28 22:14:16 +03:00
Maxim Kurnikov
32c0cbca45 add some diagnostic for unused ignores for tests typechecking (#191) 2019-09-28 21:38:56 +03:00
Anthony Ricaud
acc3ca4205 Contexts can contain Any data (#192) 2019-09-28 21:38:04 +03:00
Maxim Kurnikov
be3fc259d5 fix compatibility with 0.730 (#189) 2019-09-28 05:23:55 +03:00
Maxim Kurnikov
7725b416b6 add unused ignores reporting (#188) 2019-09-28 04:48:44 +03:00
Maxim Kurnikov
2c23d8e70f Use runtime information to determine whether class is a models.Model subclass (#182) 2019-09-28 04:05:54 +03:00
Anthony Ricaud
5910bd1b25 resolve_template accepts Sequences of str (#187)
- resolve_template is checking for lists or tuples so let's use a generic Sequence
- Union[Template, Template] seemed redundant
2019-09-25 23:32:23 +03:00
Maxim Kurnikov
963d50c717 add linting stubs with flake8-pyi and check for unused imports (#186) 2019-09-25 02:20:23 +03:00
Maxim Kurnikov
7407b93151 Fix type annotations for django.utils.safestring (#179)
* Add/fix types for django.utils.safestring.mark_safe

Django code ref: 964dd4f4f2/django/utils/safestring.py (L71-L84)

* add generic annotations for mark_safe, remove SafeBytes as it is basically deprecated

Co-authored-by: Daniel Hahler <github@thequod.de>
2019-09-23 21:17:17 +03:00
Daniel Hahler
afcd0d9293 Bump isort, use --diff (#164)
* dev-requirements: bump isort: 4.3.4 => 4.3.21

* isort: use --diff

* known_first_party = mypy_django_plugin

* Run isort
2019-09-23 20:45:43 +03:00
Maxim Kurnikov
a85dbff793 update import_all test, add some stubs for postgres (#178) 2019-09-23 19:47:11 +03:00
Maxim Kurnikov
68aebe2528 Add django.contrib.gis.db.models and django.contrib.gis.db.models.fields (#177)
* add django.contrib.gis.db.models and django.contrib.gis.db.models.fields

* install gdal in ci

* add sudo to apt

* add apt update
2019-09-23 19:30:32 +03:00
Peter Law
d3dca5b408 related_name is Optional[str] (#176)
In the current Django (2.1, 2.2), the `related_name` parameter to
`OneToOneField` and `ForeignKey` classes (much like `ManyToManyField`
and the base `ForeignObject` classes) is `Optional[str]`. While
it's true that most authors won't pass `None` here, derived field
types will want to be able to do so.
2019-09-23 17:38:34 +03:00
Peter Law
c69090ec5b Options.verbose_name_raw is always a string (#175)
At least in the current implementation.
2019-09-21 16:07:55 +03:00
Maxim Kurnikov
29ac1c3017 Split AddManagers for model in separate stages to process IncompleteDefnException properly (#171) 2019-09-18 02:20:20 +03:00
Maxim Kurnikov
23ad65033b add custom Field processing for mixins used in the Model subclasses (#167) 2019-09-18 01:40:41 +03:00
Maxim Kurnikov
64720f492c add proper stubs for django.contrib.auth.models model fields (#170) 2019-09-18 01:40:15 +03:00
Maxim Kurnikov
a8fdd4c673 cleanup some stubs in contrib.admin, contrib.admindocs (#169) 2019-09-17 23:30:49 +03:00
Maxim Kurnikov
813dd8cc1a make types for generic mixins less strict (#168) 2019-09-17 23:30:07 +03:00
Maxim Kurnikov
2b53fa5a1a Fix typecheck tests ci (#165)
* remove mention of mypy newsemanal to prepare for 0.730

* make typecheck_tests CI really work

* fix lints

* fix intentional error

* merge stderr in stdout to preserve order

Co-authored-by: Daniel Hahler <github@thequod.de>
2019-09-16 14:35:13 +03:00
Daniel Hahler
e3ea84143f WIP: fix scripts/typecheck_tests.py (#162)
* WIP: fix scripts/typecheck_tests.py

Exit non-zero if it fails to run.

Currently it fails on CI, but goes unnoticed:
https://travis-ci.com/typeddjango/django-stubs/jobs/235296115

* exit on unexpected rc, and output on stderr

* Fix

* scripts/mypy.ini: django_settings_module=scripts.django_tests_settings
2019-09-14 22:23:45 +03:00
Daniel Hahler
82e3aa5464 ci: minor cleanup (#161)
* ci: Travis: remove unnecessary option with black

Already in config, adding a final newline there.

* .travis.yml: minor cleanup
2019-09-14 21:49:13 +03:00
Daniel Hahler
5b9a467cf0 flake8: ignore certain errors for .pyi files (#159) 2019-09-14 10:52:52 +03:00
Nikita Sobolev
4a4dc53c4d Adds syntax highlight 2019-09-08 12:31:30 +03:00
Nikita Sobolev
77fd46987d Adds gitter icon 2019-09-08 12:30:41 +03:00
Nikita Sobolev
9291164a6b Adds github tempaltes, refs #112 (#155) 2019-09-06 09:16:44 +03:00
Wlises R
0c3e06e875 Solve issue 154: Fix wrong type for size in File. (#156) 2019-09-06 09:16:19 +03:00
148 changed files with 1631 additions and 626 deletions

View File

@@ -6,9 +6,7 @@ jobs:
include:
- name: Run plugin test suite with python 3.7
python: 3.7
script: |
set -e
pytest
script: 'pytest'
- name: Typecheck Django test suite with python 3.7
python: 3.7
@@ -24,18 +22,23 @@ jobs:
- name: Lint with black
python: 3.7
script: 'black --check --line-length=120 django-stubs/'
script: 'black --check django-stubs/'
- name: Lint plugin code with flake8
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'
script: 'isort --check --diff'
before_install: |
# Upgrade pip, setuptools, and wheel
sudo apt update
sudo apt install binutils libproj-dev gdal-bin
pip install -U pip setuptools wheel
install: |
pip install -r ./dev-requirements.txt
pip install -r ./dev-requirements.txt

View File

@@ -4,68 +4,81 @@
[![Build Status](https://travis-ci.org/typeddjango/django-stubs.svg?branch=master)](https://travis-ci.org/typeddjango/django-stubs)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
[![Gitter](https://badges.gitter.im/mypy-django/Lobby.svg)](https://gitter.im/mypy-django/Lobby)
This package contains type stubs and mypy plugin to provide more precise static types and type inference for Django framework. Django uses some Python "magic" that makes having precise types for some code patterns problematic. This is why we need to accompany the stubs with mypy plugins. The final goal is to be able to get precise types for most common patterns.
Supports Python 3.6/3.7, and Django 2.1/2.2.
Could be run on earlier versions of Django, but expect some missing imports warnings.
## Installation
```
```bash
pip install django-stubs
```
### WARNING: All configuration from pre-1.0.0 versions is dropped, use one below.
### WARNING: 1.0.0 breaks `dmypy`, if you need it, stay on the 0.12.x series.
## Mypy compatibility
| django-stubs | mypy version | django version | python version
| ------------ | ---- | ---- | ---- |
| 1.2.0 | 0.730 | 2.2.x | ^3.6
| 1.1.0 | 0.720 | 2.2.x | ^3.6
| 0.12.x | old semantic analyzer (<0.711), dmypy support | 2.1.x | ^3.6
## Configuration
To make mypy aware of the plugin, you need to add
```
```ini
[mypy]
plugins =
mypy_django_plugin.main
```
in your `mypy.ini` file.
in your `mypy.ini` or `setup.cfg` [file](https://mypy.readthedocs.io/en/latest/config_file.html).
Plugin requires Django settings module (what you put into `DJANGO_SETTINGS_MODULE` variable) to be specified inside `mypy.ini` file.
```
Plugin also requires Django settings module (what you put into `DJANGO_SETTINGS_MODULE` variable) to be specified.
```ini
[mypy]
strict_optional = True
; this one is new
# This one is new:
[mypy.plugins.django-stubs]
django_settings_module = mysettings
```
where `mysettings` is a value of `DJANGO_SETTINGS_MODULE` (with or without quotes)
Do you have trouble with mypy / the django plugin not finding your settings module? Try adding the root path of your project to your PYTHONPATH environment variable. If you use pipenv you can add the following to an `.env` file in your project root which pipenv will run automatically before executing any commands.:
```
PYTHONPATH=${PYTHONPATH}:${PWD}
```
Where `mysettings` is a value of `DJANGO_SETTINGS_MODULE` (with or without quotes)
New implementation uses Django runtime to extract models information, so it will crash, if your installed apps `models.py` is not correct. For this same reason, you cannot use `reveal_type` inside global scope of any Python file that will be executed for `django.setup()`.
Current implementation uses Django runtime to extract models information, so it will crash, if your installed apps `models.py` is not correct. For this same reason, you cannot use `reveal_type` inside global scope of any Python file that will be executed for `django.setup()`.
In other words, if your `manage.py runserver` crashes, mypy will crash too.
This fully working [typed boilerplate](https://github.com/wemake-services/wemake-django-template) can serve you as an example.
## Notes
Implementation monkey-patches Django to add `__class_getitem__` to the `Manager` class. If you'd use Python3.7 and do that too in your code, you can make things like
```
Type implementation monkey-patches Django to add `__class_getitem__` to the `Manager` class.
If you would use Python3.7 and do that too in your code, you can make things like
```python
class MyUserManager(models.Manager['MyUser']):
pass
class MyUser(models.Model):
objects = UserManager()
```
work, which should make a error messages a bit better.
Otherwise, custom type will be created in mypy, named `MyUser__MyUserManager`, which will rewrite base manager as `models.Manager[User]` to make methods like `get_queryset()` and others return properly typed `QuerySet`.
## To get help
We have Gitter here https://gitter.im/mypy-django/Lobby.
We have Gitter here: <https://gitter.im/mypy-django/Lobby>
If you think you have more generic typing issue, please refer to https://github.com/python/mypy and their Gitter.

View File

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

View File

@@ -1,6 +1,6 @@
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
@@ -8,8 +8,8 @@ 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 = ...

View File

@@ -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]

View File

@@ -1,3 +1,5 @@
from typing import Any, Callable, Optional
from typing import Any, Callable, Optional, Type
def register(*models: Any, site: Optional[Any] = ...) -> Callable: ...
from django.db.models.base import Model
def register(*models: Type[Model], site: Optional[Any] = ...) -> Callable: ...

View File

@@ -1,4 +1,4 @@
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union, Iterable
from django.contrib.auth.forms import AdminPasswordChangeForm
from django.forms.boundfield import BoundField
@@ -26,7 +26,7 @@ class AdminForm:
form: AdminPasswordChangeForm,
fieldsets: List[Tuple[None, Dict[str, List[str]]]],
prepopulated_fields: Dict[Any, Any],
readonly_fields: Any = ...,
readonly_fields: Optional[Iterable[Any]] = ...,
model_admin: Any = ...,
) -> None: ...
def __iter__(self) -> Iterator[Fieldset]: ...
@@ -47,7 +47,7 @@ class Fieldset:
self,
form: Any,
name: Optional[Any] = ...,
readonly_fields: Any = ...,
readonly_fields: Optional[Iterable[Any]] = ...,
fields: Any = ...,
classes: Any = ...,
description: Optional[Any] = ...,
@@ -64,7 +64,7 @@ class Fieldline:
model_admin: Any = ...
readonly_fields: Any = ...
def __init__(
self, form: Any, field: Any, readonly_fields: Optional[Any] = ..., model_admin: Optional[Any] = ...
self, form: Any, field: Any, readonly_fields: Optional[Iterable[Any]] = ..., model_admin: Optional[Any] = ...
) -> None: ...
def __iter__(self) -> Iterator[Union[AdminField, AdminReadonlyField]]: ...
def errors(self) -> SafeText: ...

View File

@@ -56,7 +56,6 @@ class BaseModelAdmin:
show_full_result_count: bool = ...
checks_class: Any = ...
def check(self, **kwargs: Any) -> List[Union[str, Error]]: ...
def __init__(self) -> None: ...
def formfield_for_dbfield(
self, db_field: Field, request: Optional[HttpRequest], **kwargs: Any
) -> Optional[Field]: ...
@@ -94,7 +93,6 @@ class BaseModelAdmin:
def has_module_permission(self, request: HttpRequest) -> bool: ...
class ModelAdmin(BaseModelAdmin):
formfield_overrides: Any
list_display: Sequence[Union[str, Callable]] = ...
list_display_links: Optional[Sequence[Union[str, Callable]]] = ...
list_filter: Sequence[Union[str, Type[ListFilter], Tuple[str, Type[ListFilter]]]] = ...
@@ -122,7 +120,6 @@ class ModelAdmin(BaseModelAdmin):
actions_on_top: bool = ...
actions_on_bottom: bool = ...
actions_selection_counter: bool = ...
checks_class: Any = ...
model: Type[Model] = ...
opts: Options = ...
admin_site: AdminSite = ...

View File

@@ -1,11 +1,11 @@
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type, Union
from django.contrib.admin.options import ModelAdmin
from django.core.handlers.wsgi import WSGIRequest
from django.db.models.base import Model
from django.http.response import HttpResponse
from django.template.response import TemplateResponse
from django.urls.resolvers import URLPattern, URLResolver
from django.urls.resolvers import URLResolver
from django.utils.functional import LazyObject
all_sites: Any
@@ -31,11 +31,11 @@ class AdminSite:
def check(self, app_configs: None) -> List[Any]: ...
def register(
self,
model_or_iterable: Union[List[Type[Model]], Tuple[Type[Model]], Type[Model]],
model_or_iterable: Union[Type[Model], Iterable[Type[Model]]],
admin_class: Optional[Type[ModelAdmin]] = ...,
**options: Any
) -> None: ...
def unregister(self, model_or_iterable: Type[Model]) -> None: ...
def unregister(self, model_or_iterable: Union[Type[Model], Iterable[Type[Model]]]) -> None: ...
def is_registered(self, model: Type[Model]) -> bool: ...
def add_action(self, action: Callable, name: None = ...) -> None: ...
def disable_action(self, name: str) -> None: ...

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.templatetags.base import InclusionAdminNode
from django.template.base import Parser, Token
from django.template.context import Context, RequestContext

View File

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

View File

@@ -1,5 +1,7 @@
from typing import Any, Callable, Optional
from typing import Callable, TypeVar, overload
def staff_member_required(
view_func: Optional[Callable] = ..., redirect_field_name: str = ..., login_url: str = ...
) -> Callable: ...
_C = TypeVar("_C", bound=Callable)
@overload
def staff_member_required(view_func: _C = ..., redirect_field_name: str = ..., login_url: str = ...) -> _C: ...
@overload
def staff_member_required(view_func: None = ..., redirect_field_name: str = ..., login_url: str = ...) -> Callable: ...

View File

@@ -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

View File

@@ -3,46 +3,17 @@ from typing import Any, Optional, Union
from django.db.models.fields import Field
from django.views.generic import TemplateView
from .utils import get_view_name
MODEL_METHODS_EXCLUDE: Any
class BaseAdminDocsView(TemplateView):
template_name: str = ...
def dispatch(self, request: Any, *args: Any, **kwargs: Any): ...
def get_context_data(self, **kwargs: Any): ...
class BookmarkletsView(BaseAdminDocsView):
template_name: str = ...
def get_context_data(self, **kwargs: Any): ...
class TemplateTagIndexView(BaseAdminDocsView):
template_name: str = ...
def get_context_data(self, **kwargs: Any): ...
class TemplateFilterIndexView(BaseAdminDocsView):
template_name: str = ...
def get_context_data(self, **kwargs: Any): ...
class ViewIndexView(BaseAdminDocsView):
template_name: str = ...
def get_context_data(self, **kwargs: Any): ...
class ViewDetailView(BaseAdminDocsView):
template_name: str = ...
def get_context_data(self, **kwargs: Any): ...
class ModelIndexView(BaseAdminDocsView):
template_name: str = ...
def get_context_data(self, **kwargs: Any): ...
class ModelDetailView(BaseAdminDocsView):
template_name: str = ...
def get_context_data(self, **kwargs: Any): ...
class TemplateDetailView(BaseAdminDocsView):
template_name: str = ...
def get_context_data(self, **kwargs: Any): ...
class BaseAdminDocsView(TemplateView): ...
class BookmarkletsView(BaseAdminDocsView): ...
class TemplateTagIndexView(BaseAdminDocsView): ...
class TemplateFilterIndexView(BaseAdminDocsView): ...
class ViewIndexView(BaseAdminDocsView): ...
class ViewDetailView(BaseAdminDocsView): ...
class ModelIndexView(BaseAdminDocsView): ...
class ModelDetailView(BaseAdminDocsView): ...
class TemplateDetailView(BaseAdminDocsView): ...
def get_return_data_type(func_name: Any): ...
def get_readable_field_data_type(field: Union[Field, str]) -> str: ...

View File

@@ -13,14 +13,12 @@ class BaseUserManager(models.Manager[_T]):
def get_by_natural_key(self, username: Optional[str]) -> _T: ...
class AbstractBaseUser(models.Model):
password: models.CharField = ...
last_login: models.DateTimeField = ...
is_active: models.BooleanField = ...
password = models.CharField(max_length=128)
last_login = models.DateTimeField(blank=True, null=True)
REQUIRED_FIELDS: List[str] = ...
class Meta: ...
def get_username(self) -> str: ...
def clean(self) -> None: ...
def save(self, *args: Any, **kwargs: Any) -> None: ...
def natural_key(self) -> Tuple[str]: ...
@property
def is_anonymous(self) -> bool: ...

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(
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

View File

@@ -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

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.http.response import HttpResponse, HttpResponseRedirect

View File

@@ -15,17 +15,17 @@ class PermissionManager(models.Manager):
class Permission(models.Model):
content_type_id: int
name: models.CharField = ...
content_type: models.ForeignKey = models.ForeignKey(ContentType, on_delete=models.CASCADE)
codename: models.CharField = ...
name = models.CharField(max_length=255)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
codename = models.CharField(max_length=100)
def natural_key(self) -> Tuple[str, str, str]: ...
class GroupManager(models.Manager):
def get_by_natural_key(self, name: str) -> Group: ...
class Group(models.Model):
name: models.CharField = ...
permissions: models.ManyToManyField = models.ManyToManyField(Permission)
name = models.CharField(max_length=150)
permissions = models.ManyToManyField(Permission)
def natural_key(self): ...
_T = TypeVar("_T", bound=Model)
@@ -39,7 +39,7 @@ class UserManager(BaseUserManager[_T]):
) -> _T: ...
class PermissionsMixin(models.Model):
is_superuser: models.BooleanField = ...
is_superuser = models.BooleanField()
groups: models.ManyToManyField = models.ManyToManyField(Group)
user_permissions: models.ManyToManyField = models.ManyToManyField(Permission)
def get_group_permissions(self, obj: None = ...) -> Set[str]: ...
@@ -50,15 +50,17 @@ class PermissionsMixin(models.Model):
class AbstractUser(AbstractBaseUser, PermissionsMixin): # type: ignore
username_validator: UnicodeUsernameValidator = ...
username: models.CharField = ...
first_name: models.CharField = ...
last_name: models.CharField = ...
email: models.EmailField = ...
is_staff: models.BooleanField = ...
date_joined: models.DateTimeField = ...
username = models.CharField(max_length=150)
first_name = models.CharField(max_length=30, blank=True)
last_name = models.CharField(max_length=150, blank=True)
email = models.EmailField(blank=True)
is_staff = models.BooleanField()
is_active = models.BooleanField()
date_joined = models.DateTimeField()
EMAIL_FIELD: str = ...
USERNAME_FIELD: str = ...
def clean(self) -> None: ...
def get_full_name(self) -> str: ...
def get_short_name(self) -> str: ...
def email_user(self, subject: str, message: str, from_email: str = ..., **kwargs: Any) -> None: ...

View File

@@ -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

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_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.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]

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.response import HttpResponseRedirect

View File

@@ -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

View File

View File

View File

@@ -0,0 +1,13 @@
from django.db.models import *
from .fields import (
GeometryField as GeometryField,
LineStringField as LineStringField,
MultiLineStringField as MultiLineStringField,
MultiPointField as MultiPointField,
MultiPolygonField as MultiPolygonField,
PointField as PointField,
PolygonField as PolygonField,
GeometryCollectionField as GeometryCollectionField,
RasterField as RasterField,
)

View File

@@ -0,0 +1,91 @@
from typing import Any, Iterable, NamedTuple, Optional, TypeVar, Union, Tuple
from django.db.models.fields import Field, _ErrorMessagesToOverride, _FieldChoices, _ValidatorCallable
_Connection = Any
# __set__ value type
_ST = TypeVar("_ST")
# __get__ return type
_GT = TypeVar("_GT")
class SRIDCacheEntry(NamedTuple):
units: Any
units_name: str
geodetic: bool
spheroid: str
def get_srid_info(srid: int, connection: _Connection) -> SRIDCacheEntry: ...
class BaseSpatialField(Field[_ST, _GT]):
def __init__(
self,
verbose_name: Optional[Union[str, bytes]] = ...,
srid: int = ...,
spatial_index: bool = ...,
name: Optional[str] = ...,
primary_key: bool = ...,
max_length: Optional[int] = ...,
unique: bool = ...,
blank: bool = ...,
null: bool = ...,
db_index: bool = ...,
default: Any = ...,
editable: bool = ...,
auto_created: bool = ...,
serialize: bool = ...,
unique_for_date: Optional[str] = ...,
unique_for_month: Optional[str] = ...,
unique_for_year: Optional[str] = ...,
choices: Optional[_FieldChoices] = ...,
help_text: str = ...,
db_column: Optional[str] = ...,
db_tablespace: Optional[str] = ...,
validators: Iterable[_ValidatorCallable] = ...,
error_messages: Optional[_ErrorMessagesToOverride] = ...,
): ...
def spheroid(self, connection: _Connection) -> str: ...
def units(self, connection: _Connection) -> Any: ...
def units_name(self, connection: _Connection) -> str: ...
def geodetic(self, connection: _Connection) -> bool: ...
class GeometryField(BaseSpatialField):
def __init__(
self,
verbose_name: Optional[Union[str, bytes]] = ...,
dim: int = ...,
geography: bool = ...,
extent: Tuple[float, float, float, float] = ...,
tolerance: float = ...,
srid: int = ...,
spatial_index: bool = ...,
name: Optional[str] = ...,
primary_key: bool = ...,
max_length: Optional[int] = ...,
unique: bool = ...,
blank: bool = ...,
null: bool = ...,
db_index: bool = ...,
default: Any = ...,
editable: bool = ...,
auto_created: bool = ...,
serialize: bool = ...,
unique_for_date: Optional[str] = ...,
unique_for_month: Optional[str] = ...,
unique_for_year: Optional[str] = ...,
choices: Optional[_FieldChoices] = ...,
help_text: str = ...,
db_column: Optional[str] = ...,
db_tablespace: Optional[str] = ...,
validators: Iterable[_ValidatorCallable] = ...,
error_messages: Optional[_ErrorMessagesToOverride] = ...,
): ...
class PointField(GeometryField): ...
class LineStringField(GeometryField): ...
class PolygonField(GeometryField): ...
class MultiPointField(GeometryField): ...
class MultiLineStringField(GeometryField): ...
class MultiPolygonField(GeometryField): ...
class GeometryCollectionField(GeometryField): ...
class RasterField(BaseSpatialField): ...

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.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.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]: ...

View File

@@ -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

View File

@@ -0,0 +1,24 @@
from .general import (
ArrayAgg as ArrayAgg,
BitAnd as BitAnd,
BitOr as BitOr,
BoolAnd as BoolAnd,
BoolOr as BoolOr,
JSONBAgg as JSONBAgg,
StringAgg as StringAgg,
)
from .statistics import (
Corr as Corr,
CovarPop as CovarPop,
RegrAvgX as RegrAvgX,
RegrAvgY as RegrAvgY,
RegrCount as RegrCount,
RegrIntercept as RegrIntercept,
RegrR2 as RegrR2,
RegrSlope as RegrSlope,
RegrSXX as RegrSXX,
RegrSXY as RegrSXY,
RegrSYY as RegrSYY,
StatAggregate as StatAggregate,
)

View File

@@ -0,0 +1,11 @@
from django.db.models.aggregates import Aggregate
from .mixins import OrderableAggMixin
class ArrayAgg(OrderableAggMixin, Aggregate): ...
class BitAnd(Aggregate): ...
class BitOr(Aggregate): ...
class BoolAnd(Aggregate): ...
class BoolOr(Aggregate): ...
class JSONBAgg(Aggregate): ...
class StringAgg(OrderableAggMixin, Aggregate): ...

View File

@@ -0,0 +1 @@
class OrderableAggMixin: ...

View File

@@ -0,0 +1,14 @@
from django.db.models.aggregates import Aggregate
class StatAggregate(Aggregate): ...
class Corr(StatAggregate): ...
class CovarPop(StatAggregate): ...
class RegrAvgX(StatAggregate): ...
class RegrAvgY(StatAggregate): ...
class RegrCount(StatAggregate): ...
class RegrIntercept(StatAggregate): ...
class RegrR2(StatAggregate): ...
class RegrSlope(StatAggregate): ...
class RegrSXX(StatAggregate): ...
class RegrSXY(StatAggregate): ...
class RegrSYY(StatAggregate): ...

View File

@@ -1,29 +1,82 @@
from typing import Any, Optional
from typing import Optional, Sequence
from django.db.models.query_utils import Q
from django.db.models import Index
class PostgresIndex(Index):
@property
def max_name_length(self) -> int: ...
class PostgresIndex(Index): ...
class BrinIndex(PostgresIndex):
def __init__(
self, *, autosummarize: Optional[bool] = ..., pages_per_range: Optional[int] = ..., **kwargs: Any
self,
*,
autosummarize: Optional[bool] = ...,
pages_per_range: Optional[int] = ...,
fields: Sequence[str] = ...,
name: Optional[str] = ...,
db_tablespace: Optional[str] = ...,
opclasses: Sequence[str] = ...,
condition: Optional[Q] = ...
) -> None: ...
class BTreeIndex(PostgresIndex):
def __init__(self, *, fillfactor: Optional[int] = ..., **kwargs: Any): ...
def __init__(
self,
*,
fillfactor: Optional[int] = ...,
fields: Sequence[str] = ...,
name: Optional[str] = ...,
db_tablespace: Optional[str] = ...,
opclasses: Sequence[str] = ...,
condition: Optional[Q] = ...
) -> None: ...
class GinIndex(PostgresIndex):
def __init__(
self, *, fastupdate: Optional[bool] = ..., gin_pending_list_limit: Optional[int] = ..., **kwargs: Any
self,
*,
fastupdate: Optional[bool] = ...,
gin_pending_list_limit: Optional[int] = ...,
fields: Sequence[str] = ...,
name: Optional[str] = ...,
db_tablespace: Optional[str] = ...,
opclasses: Sequence[str] = ...,
condition: Optional[Q] = ...
) -> None: ...
class GistIndex(PostgresIndex):
def __init__(self, *, buffering: Optional[bool] = ..., fillfactor: Optional[int] = ..., **kwargs: Any) -> None: ...
def __init__(
self,
*,
buffering: Optional[bool] = ...,
fillfactor: Optional[int] = ...,
fields: Sequence[str] = ...,
name: Optional[str] = ...,
db_tablespace: Optional[str] = ...,
opclasses: Sequence[str] = ...,
condition: Optional[Q] = ...
) -> None: ...
class HashIndex(PostgresIndex):
def __init__(self, *, fillfactor: Optional[int] = ..., **kwargs: Any) -> None: ...
def __init__(
self,
*,
fillfactor: Optional[int] = ...,
fields: Sequence[str] = ...,
name: Optional[str] = ...,
db_tablespace: Optional[str] = ...,
opclasses: Sequence[str] = ...,
condition: Optional[Q] = ...
) -> None: ...
class SpGistIndex(PostgresIndex):
def __init__(self, *, fillfactor: Optional[int] = ..., **kwargs: Any) -> None: ...
def __init__(
self,
*,
fillfactor: Optional[int] = ...,
fields: Sequence[str] = ...,
name: Optional[str] = ...,
db_tablespace: Optional[str] = ...,
opclasses: Sequence[str] = ...,
condition: Optional[Q] = ...
) -> None: ...

View File

@@ -0,0 +1,18 @@
from django.db.models.lookups import Exact
from django.db.models import Lookup, Transform
from .search import SearchVectorExact
class PostgresSimpleLookup(Lookup):
operator: str
class DataContains(PostgresSimpleLookup): ...
class ContainedBy(PostgresSimpleLookup): ...
class Overlap(PostgresSimpleLookup): ...
class HasKey(PostgresSimpleLookup): ...
class HasKeys(PostgresSimpleLookup): ...
class HasAnyKeys(HasKeys): ...
class Unaccent(Transform): ...
class SearchLookup(SearchVectorExact): ...
class TrigramSimilar(PostgresSimpleLookup): ...
class JSONExact(Exact): ...

View File

@@ -1,10 +1,12 @@
from typing import Any, Dict, Optional, TypeVar, Union
from django.db.models.expressions import Combinable, CombinedExpression, Func, Value
from django.db.models.expressions import Combinable, CombinedExpression, Func, Value, _OutputField
from django.db.models.lookups import Lookup
from django.db.models import Field
_Expression = Union[str, Combinable, "SearchQueryCombinable"]
class SearchVectorExact(Lookup): ...
class SearchVectorField(Field): ...
class SearchQueryField(Field): ...
@@ -14,10 +16,12 @@ class SearchVectorCombinable:
class SearchVector(SearchVectorCombinable, Func):
config: Optional[Any] = ...
def __init__(self, *expressions: Union[str, Combinable], **extra: Any): ...
def __init__(self, *expressions: _Expression, **extra: Any): ...
class CombinedSearchVector(SearchVectorCombinable, CombinedExpression):
def __init__(self, lhs, connector, rhs, config, output_field: Optional[Field, str] = ...): ...
def __init__(
self, lhs, connector, rhs, config: Optional[_Expression] = ..., output_field: Optional[_OutputField] = ...
): ...
_T = TypeVar("_T", bound="SearchQueryCombinable")
@@ -29,19 +33,31 @@ class SearchQueryCombinable:
def __and__(self: _T, other: SearchQueryCombinable) -> _T: ...
def __rand__(self: _T, other: SearchQueryCombinable) -> _T: ...
class SearchQuery(SearchQueryCombinable, Value):
SEARCH_TYPES: Dict[str, str] = {"plain": "plainto_tsquery", "phrase": "phraseto_tsquery", "raw": "to_tsquery"}
def __init__(self, value, output_field=..., *, config=..., invert=False, search_type="plain"): ...
class SearchQuery(SearchQueryCombinable, Value): # type: ignore
SEARCH_TYPES: Dict[str, str] = ...
def __init__(
self,
value: str,
output_field: Optional[_OutputField] = ...,
*,
config: Optional[_Expression] = ...,
invert: bool = ...,
search_type: str = ...
): ...
def __invert__(self: _T) -> _T: ...
class CombinedSearchQuery(SearchQueryCombinable, CombinedExpression):
def __init__(self, lhs, connector, rhs, config, output_field=...) -> None: ...
class CombinedSearchQuery(SearchQueryCombinable, CombinedExpression): # type: ignore
def __init__(
self, lhs, connector, rhs, config: Optional[_Expression] = ..., output_field: Optional[_OutputField] = ...
) -> None: ...
class SearchRank(Func):
def __init__(self, vector, query, **extra: Any) -> None: ...
def __init__(
self, vector: Union[SearchVector, _Expression], query: Union[SearchQuery, _Expression], **extra: Any
) -> None: ...
class TrigramBase(Func):
def __init__(self, expression, string, **extra: Any) -> None: ...
def __init__(self, expression: _Expression, string, **extra: Any) -> None: ...
class TrigramSimilarity(TrigramBase): ...
class TrigramDistance(TrigramBase): ...

View File

@@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import Any, List
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.storage import FileSystemStorage
from django.utils.functional import LazyObject
from django.utils.safestring import SafeText
class StaticFilesStorage(FileSystemStorage):
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.templatetags.static import StaticNode

View File

@@ -0,0 +1,3 @@
from django.test import LiveServerTestCase
class StaticLiveServerTestCase(LiveServerTestCase): ...

View File

@@ -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

View File

@@ -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

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.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

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]: ...

View File

@@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import Any, List
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

View File

@@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import Any, List
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

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.urls.resolvers import URLPattern, URLResolver

View File

@@ -14,6 +14,7 @@ class File(FileProxyMixin, IO[Any]):
def __init__(self, file: Any, name: Optional[str] = ...) -> None: ...
def __bool__(self) -> bool: ...
def __len__(self) -> int: ...
@property
def size(self) -> int: ...
def chunks(self, chunk_size: Optional[int] = ...) -> Iterator[bytes]: ...
def multiple_chunks(self, chunk_size: Optional[int] = ...) -> bool: ...

View File

@@ -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): ...

View File

@@ -63,7 +63,7 @@ class BaseCommand:
fail_level: int = ...,
) -> None: ...
def check_migrations(self) -> None: ...
def handle(self, *args: Any, **options: Any) -> None: ...
def handle(self, *args: Any, **options: Any) -> Optional[str]: ...
class AppCommand(BaseCommand):
missing_args_message: str = ...

View File

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

View File

@@ -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 = ...

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.query import QuerySet
@@ -32,7 +32,9 @@ class Paginator:
def validate_number(self, number: Optional[Union[float, str]]) -> int: ...
def get_page(self, number: Optional[int]) -> Page: ...
def page(self, number: Union[int, str]) -> Page: ...
@property
def count(self) -> int: ...
@property
def num_pages(self) -> int: ...
@property
def page_range(self) -> range: ...

View File

@@ -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 = ...

View File

@@ -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): ...

View File

@@ -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

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Any
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

View File

@@ -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 = ...

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.models.fields import Field
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

View File

@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional
from typing import Dict
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 typing import Any, Callable, Iterator
from typing import Any, Callable
from django.db.backends.base.base import BaseDatabaseWrapper

View File

@@ -1,7 +1,7 @@
import types
from datetime import date, datetime, time
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
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.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.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.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

View File

@@ -5,6 +5,7 @@ from django.db.models.expressions import Func
class Aggregate(Func):
filter_template: str = ...
filter: Any = ...
allow_distinct: bool = ...
def __init__(self, *expressions: Any, distinct: bool = ..., filter: Optional[Any] = ..., **extra: Any) -> None: ...
class Avg(Aggregate): ...

View File

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

View File

@@ -43,6 +43,7 @@ _GT = TypeVar("_GT")
class Field(RegisterLookupMixin, Generic[_ST, _GT]):
_pyi_private_set_type: Any
_pyi_private_get_type: Any
_pyi_lookup_exact_type: Any
widget: Widget
help_text: str
@@ -55,9 +56,11 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
model: Type[Model]
name: str
verbose_name: str
description: str
blank: bool = ...
null: bool = ...
editable: bool = ...
empty_strings_allowed: bool = ...
choices: Optional[_FieldChoices] = ...
db_column: Optional[str]
column: str
@@ -129,6 +132,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
class IntegerField(Field[_ST, _GT]):
_pyi_private_set_type: Union[float, int, str, Combinable]
_pyi_private_get_type: int
_pyi_lookup_exact_type: int
class PositiveIntegerRelDbTypeMixin:
def rel_db_type(self, connection: Any): ...
@@ -141,10 +145,12 @@ class BigIntegerField(IntegerField[_ST, _GT]): ...
class FloatField(Field[_ST, _GT]):
_pyi_private_set_type: Union[float, int, str, Combinable]
_pyi_private_get_type: float
_pyi_lookup_exact_type: float
class DecimalField(Field[_ST, _GT]):
_pyi_private_set_type: Union[str, float, decimal.Decimal, Combinable]
_pyi_private_get_type: decimal.Decimal
_pyi_lookup_exact_type: Union[str, decimal.Decimal]
# attributes
max_digits: int = ...
decimal_places: int = ...
@@ -174,10 +180,13 @@ class DecimalField(Field[_ST, _GT]):
class AutoField(Field[_ST, _GT]):
_pyi_private_set_type: Union[Combinable, int, str]
_pyi_private_get_type: int
_pyi_lookup_exact_type: int
class CharField(Field[_ST, _GT]):
_pyi_private_set_type: Union[str, int, Combinable]
_pyi_private_get_type: str
# objects are converted to string before comparison
_pyi_lookup_exact_type: Any
def __init__(
self,
verbose_name: Optional[Union[str, bytes]] = ...,
@@ -236,14 +245,18 @@ class URLField(CharField[_ST, _GT]): ...
class TextField(Field[_ST, _GT]):
_pyi_private_set_type: Union[str, Combinable]
_pyi_private_get_type: str
# objects are converted to string before comparison
_pyi_lookup_exact_type: Any
class BooleanField(Field[_ST, _GT]):
_pyi_private_set_type: Union[bool, Combinable]
_pyi_private_get_type: bool
_pyi_lookup_exact_type: bool
class NullBooleanField(Field[_ST, _GT]):
_pyi_private_set_type: Optional[Union[bool, Combinable]]
_pyi_private_get_type: Optional[bool]
_pyi_lookup_exact_type: Optional[bool]
class IPAddressField(Field[_ST, _GT]):
_pyi_private_set_type: Union[str, Combinable]
@@ -284,6 +297,7 @@ class DateTimeCheckMixin: ...
class DateField(DateTimeCheckMixin, Field[_ST, _GT]):
_pyi_private_set_type: Union[str, date, Combinable]
_pyi_private_get_type: date
_pyi_lookup_exact_type: Union[str, date]
def __init__(
self,
verbose_name: Optional[Union[str, bytes]] = ...,
@@ -336,6 +350,7 @@ class TimeField(DateTimeCheckMixin, Field[_ST, _GT]):
class DateTimeField(DateField[_ST, _GT]):
_pyi_private_get_type: datetime
_pyi_lookup_exact_type: Union[str, datetime]
class UUIDField(Field[_ST, _GT]):
_pyi_private_set_type: Union[str, uuid.UUID]

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.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.fields import Field, _FieldChoices, _ValidatorCallable, _ErrorMessagesToOverride
from django.forms import fields as form_fields
BLANK_CHOICE_DASH: List[Tuple[str, str]] = ...

View File

@@ -1,43 +1,27 @@
from typing import (
Any,
Callable,
Dict,
Iterable,
List,
Optional,
Sequence,
TYPE_CHECKING,
Tuple,
Type,
TypeVar,
Union,
overload,
)
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple, Type, TypeVar, Union, overload
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.fields.mixins import FieldCacheMixin
from django.db.models.query_utils import PathInfo, Q
from django.db import models
from django.db.models import Field, Model
from django.db.models.fields.related_descriptors import (
from django.db.models.fields.related_descriptors import ( # noqa: F401
ForwardOneToOneDescriptor as ForwardOneToOneDescriptor,
ForwardManyToOneDescriptor as ForwardManyToOneDescriptor,
ManyToManyDescriptor as ManyToManyDescriptor,
ReverseOneToOneDescriptor as ReverseOneToOneDescriptor,
ReverseManyToOneDescriptor as ReverseManyToOneDescriptor,
)
from django.db.models.fields.reverse_related import (
from django.db.models.fields.reverse_related import ( # noqa: F401
ForeignObjectRel as ForeignObjectRel,
OneToOneRel as OneToOneRel,
ManyToOneRel as ManyToOneRel,
ManyToManyRel as ManyToManyRel,
)
if TYPE_CHECKING:
from django.db.models.manager import RelatedManager
_T = TypeVar("_T", bound=models.Model)
_F = TypeVar("_F", bound=models.Field)
_Choice = Tuple[Any, str]
@@ -114,7 +98,7 @@ class ForeignKey(ForeignObject[_ST, _GT]):
to: Union[Type[Model], str],
on_delete: Callable[..., None],
to_field: Optional[str] = ...,
related_name: str = ...,
related_name: Optional[str] = ...,
related_query_name: Optional[str] = ...,
limit_choices_to: Optional[Union[Dict[str, Any], Callable[[], Any], Q]] = ...,
parent_link: bool = ...,
@@ -159,7 +143,7 @@ class OneToOneField(RelatedField[_ST, _GT]):
to: Union[Type[Model], str],
on_delete: Any,
to_field: Optional[str] = ...,
related_name: str = ...,
related_name: Optional[str] = ...,
related_query_name: Optional[str] = ...,
limit_choices_to: Optional[Union[Dict[str, Any], Callable[[], Any], Q]] = ...,
parent_link: bool = ...,

View File

@@ -1,12 +1,12 @@
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
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.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.fields import AutoField, Field
from .mixins import FieldCacheMixin
class ForeignObjectRel(FieldCacheMixin):

View File

@@ -1,18 +1,18 @@
from collections import OrderedDict
from datetime import datetime
from typing import Any, Dict, Iterable, List, Optional, Tuple, Type, Union, Mapping
from typing import Any, Iterable, List, Optional, Tuple, Type, Union, Mapping, TypeVar, Generic
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.sql.compiler import SQLCompiler
from django.db.models.sql.query import Query
from django.utils.datastructures import OrderedSet
from django.utils.safestring import SafeText
from django.db.models.fields import TextField, related_lookups
class Lookup:
_T = TypeVar("_T")
class Lookup(Generic[_T]):
lookup_name: str = ...
prepare_rhs: bool = ...
can_use_none_as_rhs: bool = ...
@@ -49,7 +49,7 @@ class Transform(RegisterLookupMixin, Func):
def lhs(self) -> Expression: ...
def get_bilateral_transforms(self) -> List[Type[Transform]]: ...
class BuiltinLookup(Lookup):
class BuiltinLookup(Lookup[_T]):
def get_rhs_op(self, connection: DatabaseWrapper, rhs: str) -> str: ...
class FieldGetDbPrepValueMixin:
@@ -64,21 +64,21 @@ class FieldGetDbPrepValueIterableMixin(FieldGetDbPrepValueMixin):
class Exact(FieldGetDbPrepValueMixin, BuiltinLookup): ...
class IExact(BuiltinLookup): ...
class GreaterThan(FieldGetDbPrepValueMixin, BuiltinLookup): ...
class GreaterThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup): ...
class LessThan(FieldGetDbPrepValueMixin, BuiltinLookup): ...
class GreaterThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup[_T]): ...
class LessThan(FieldGetDbPrepValueMixin, BuiltinLookup[_T]): ...
class LessThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup): ...
class IntegerFieldFloatRounding:
rhs: Any = ...
def get_prep_lookup(self) -> Any: ...
class IntegerGreaterThanOrEqual(IntegerFieldFloatRounding, GreaterThanOrEqual): ...
class IntegerLessThan(IntegerFieldFloatRounding, LessThan): ...
class IntegerGreaterThanOrEqual(IntegerFieldFloatRounding, GreaterThanOrEqual[Union[int, float]]): ...
class IntegerLessThan(IntegerFieldFloatRounding, LessThan[Union[int, float]]): ...
class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup):
def split_parameter_list_as_sql(self, compiler: Any, connection: Any): ...
class PatternLookup(BuiltinLookup):
class PatternLookup(BuiltinLookup[str]):
param_pattern: str = ...
class Contains(PatternLookup): ...
@@ -88,8 +88,8 @@ class IStartsWith(StartsWith): ...
class EndsWith(PatternLookup): ...
class IEndsWith(EndsWith): ...
class Range(FieldGetDbPrepValueIterableMixin, BuiltinLookup): ...
class IsNull(BuiltinLookup): ...
class Regex(BuiltinLookup): ...
class IsNull(BuiltinLookup[bool]): ...
class Regex(BuiltinLookup[str]): ...
class IRegex(Regex): ...
class YearLookup(Lookup):

View File

@@ -1,5 +1,5 @@
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.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.models.base import Model
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.manager import Manager
from django.db.models.query_utils import PathInfo
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
EMPTY_RELATION_TREE: Any
@@ -51,7 +51,7 @@ class Options(Generic[_M]):
verbose_name: Optional[str] = ...
verbose_name_plural: Optional[str] = ...
db_table: str = ...
ordering: Optional[List[str]] = ...
ordering: Optional[Sequence[str]] = ...
indexes: List[Any] = ...
unique_together: Union[List[Any], Tuple] = ...
index_together: Union[List[Any], Tuple] = ...
@@ -97,7 +97,7 @@ class Options(Generic[_M]):
def setup_proxy(self, target: Type[Model]) -> None: ...
def can_migrate(self, connection: Union[DatabaseWrapper, str]) -> bool: ...
@property
def verbose_name_raw(self) -> Any: ...
def verbose_name_raw(self) -> str: ...
@property
def swapped(self) -> Optional[str]: ...
@property

View File

@@ -1,7 +1,9 @@
import datetime
from typing import (
Any,
Collection,
Dict,
Generic,
Iterable,
Iterator,
List,
@@ -14,18 +16,15 @@ from typing import (
TypeVar,
Union,
overload,
Generic,
NamedTuple,
Collection,
)
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 import models
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)
_QS = TypeVar("_QS", bound="_BaseQuerySet")
@@ -43,8 +42,7 @@ class _BaseQuerySet(Generic[_T], Sized):
def as_manager(cls) -> Manager[Any]: ...
def __len__(self) -> int: ...
def __bool__(self) -> bool: ...
def __class_getitem__(cls, item: Type[_T]):
pass
def __class_getitem__(cls, item: Type[_T]): ...
def __getstate__(self) -> Dict[str, Any]: ...
# Technically, the other QuerySet must be of the same type _T, but _T is covariant
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

View File

@@ -38,5 +38,5 @@ def atomic(using: _C) -> _C: ...
# Decorator or context-manager with parameters
@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: ...

View File

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

View File

@@ -1,6 +1,5 @@
from datetime import datetime, timedelta
from decimal import Decimal
from typing import Any, Callable, List, Optional, Pattern, Sequence, Type, Union, Tuple, Iterable
from typing import Any, Callable, Iterable, List, Optional, Pattern, Sequence, Tuple, Type, Union
from django.core.validators import BaseValidator
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.forms.boundfield import BoundField
@@ -8,8 +8,7 @@ from django.forms.utils import ErrorDict, ErrorList
from django.forms.widgets import Media, MediaDefiningClass
from django.utils.safestring import SafeText
class DeclarativeFieldsMetaclass(MediaDefiningClass):
def __new__(mcs, name: str, bases: Sequence[Type[BaseForm]], attrs: Dict[str, Any]) -> Type[BaseForm]: ...
class DeclarativeFieldsMetaclass(MediaDefiningClass): ...
class BaseForm:
class Meta:

View File

@@ -54,8 +54,7 @@ class ModelFormOptions:
field_classes: Optional[Dict[str, Type[Field]]] = ...
def __init__(self, options: Optional[type] = ...) -> None: ...
class ModelFormMetaclass(DeclarativeFieldsMetaclass):
def __new__(mcs, name: str, bases: Sequence[Type[Any]], attrs: Dict[str, Any]) -> Type[ModelForm]: ...
class ModelFormMetaclass(DeclarativeFieldsMetaclass): ...
class BaseModelForm(BaseForm):
instance: Any = ...
@@ -73,7 +72,6 @@ class BaseModelForm(BaseForm):
use_required_attribute: Optional[bool] = ...,
renderer: Any = ...,
) -> None: ...
def clean(self) -> Dict[str, Any]: ...
def validate_unique(self) -> None: ...
save_m2m: Any = ...
def save(self, commit: bool = ...) -> Any: ...

View File

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

View File

@@ -27,8 +27,7 @@ class Media:
def merge(list_1: Iterable[Any], list_2: Iterable[Any]) -> Iterable[Any]: ...
def __add__(self, other: Media) -> Media: ...
class MediaDefiningClass(type):
def __new__(mcs, name: str, bases: Sequence[Any], attrs: Dict[str, Any]) -> type: ...
class MediaDefiningClass(type): ...
class Widget:
needs_multipart_form: bool = ...
@@ -70,9 +69,7 @@ class HiddenInput(Input):
choices: Iterable[Tuple[str, str]]
class MultipleHiddenInput(HiddenInput): ...
class FileInput(Input):
needs_multipart_form: bool = ...
class FileInput(Input): ...
class ClearableFileInput(FileInput):
clear_checkbox_label: Any = ...
@@ -102,7 +99,7 @@ class ChoiceWidget(Widget):
allow_multiple_selected: bool = ...
input_type: Optional[str] = ...
template_name: Optional[str] = ...
option_template_name: Any = ...
option_template_name: str = ...
add_id_index: bool = ...
checked_attribute: Any = ...
option_inherits_attrs: bool = ...
@@ -130,10 +127,8 @@ class SelectMultiple(Select):
class RadioSelect(ChoiceWidget):
can_add_related: bool
option_template_name: str = ...
class CheckboxSelectMultiple(ChoiceWidget):
def id_for_label(self, id_: str, index: Optional[str] = ...) -> str: ...
class CheckboxSelectMultiple(ChoiceWidget): ...
class MultiWidget(Widget):
template_name: str = ...

View File

@@ -10,17 +10,16 @@ from typing import (
Pattern,
Set,
Tuple,
Type,
TypeVar,
Union,
overload,
TypeVar,
Type,
)
from django.contrib.auth.base_user import AbstractBaseUser
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.contrib.auth.base_user import AbstractBaseUser
from django.core.files import uploadedfile, uploadhandler
from django.urls import ResolverMatch

View File

@@ -48,8 +48,8 @@ class HttpResponseBase(Iterable[Any]):
samesite: 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 delete_cookie(self, key: str, path: str = "", domain: Optional[str] = ...) -> 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 make_bytes(self, value: object) -> bytes: ...
def close(self) -> None: ...
def write(self, content: Union[str, bytes]) -> None: ...

View File

@@ -22,8 +22,7 @@ def render(
using: Optional[str] = ...,
) -> HttpResponse: ...
class SupportsGetAbsoluteUrl(Protocol):
pass
class SupportsGetAbsoluteUrl(Protocol): ...
def redirect(
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.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 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

View File

@@ -1,8 +1,8 @@
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.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 select_template(template_name_list: Union[List[str], str], using: Optional[str] = ...) -> Any: ...

View File

@@ -1,13 +1,12 @@
import functools
from http.cookies import SimpleCookie
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
from django.core.handlers.wsgi import WSGIRequest
from django.http.request import HttpRequest
from django.template.base import Template
from django.template.context import RequestContext
from django.test.client import Client
from django.utils.functional import SimpleLazyObject
from django.http import HttpResponse
@@ -20,7 +19,7 @@ class SimpleTemplateResponse(HttpResponse):
status_code: int
rendering_attrs: Any = ...
template_name: Union[List[str], Template, str] = ...
context_data: Optional[Dict[str, str]] = ...
context_data: Optional[Dict[str, Any]] = ...
using: Optional[str] = ...
def __init__(
self,
@@ -31,7 +30,7 @@ class SimpleTemplateResponse(HttpResponse):
charset: Optional[str] = ...,
using: Optional[str] = ...,
) -> None: ...
def resolve_template(self, template: Union[List[str], Template, str]) -> Union[Template, Template]: ...
def resolve_template(self, template: Union[Sequence[str], Template, str]) -> Template: ...
def resolve_context(self, context: Optional[Dict[str, Any]]) -> Optional[Dict[str, Any]]: ...
@property
def rendered_content(self) -> str: ...

Some files were not shown because too many files have changed in this diff Show More