You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package contains [type stubs](https://www.python.org/dev/peps/pep-0561/) and a custom 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 this project. The final goal is to be able to get precise types for most common patterns.
12
11
13
-
14
12
## Installation
15
13
16
14
```bash
@@ -68,7 +66,6 @@ We rely on different `django` and `mypy` versions:
68
66
| 1.1.0 | 0.720 | 2.2.x | ^3.6
69
67
| 0.12.x | old semantic analyzer (<0.711), dmypy support | 2.1.x | ^3.6
70
68
71
-
72
69
## FAQ
73
70
74
71
### Is this an official Django project?
@@ -128,6 +125,7 @@ Django's built in [`HttpRequest`](https://docs.djangoproject.com/en/4.0/ref/requ
128
125
```python
129
126
Union[User, AnonymousUser]
130
127
```
128
+
131
129
where `User` is the user model specified by the `AUTH_USER_MODEL` setting.
132
130
133
131
If you want a `HttpRequest` that you can type-annotate with where you know that the user is authenticated you can subclass the normal `HttpRequest` class like so:
@@ -143,7 +141,6 @@ class AuthenticatedHttpRequest(HttpRequest):
143
141
144
142
And then use `AuthenticatedHttpRequest` instead of the standard `HttpRequest` for when you know that the user is authenticated. For example in views using the `@login_required` decorator.
145
143
146
-
147
144
### My QuerySet methods are returning Any rather than my Model
148
145
149
146
If you are using `MyQuerySet.as_manager()`:
@@ -208,9 +205,7 @@ class MyManager(model.Manager):
208
205
209
206
will cause this error message:
210
207
211
-
```
212
-
error: Return type "MyModel" of "create" incompatible with return type "_T" in supertype "BaseManager"
213
-
```
208
+
> error: Return type "MyModel" of "create" incompatible with return type "_T" in supertype "BaseManager"
214
209
215
210
This is happening because the `Manager` class is generic, but without
216
211
specifying generics the built-in manager methods are expected to return the
-[`awesome-python-typing`](https://github.com/typeddjango/awesome-python-typing) - Awesome list of all typing-related things in Python.
303
297
-[`djangorestframework-stubs`](https://github.com/typeddjango/djangorestframework-stubs) - Stubs for Django REST Framework.
304
298
-[`pytest-mypy-plugins`](https://github.com/typeddjango/pytest-mypy-plugins) - `pytest` plugin that we use for testing `mypy` stubs and plugins.
305
299
-[`wemake-django-template`](https://github.com/wemake-services/wemake-django-template) - Create new typed Django projects in seconds.
306
300
307
-
308
-
309
301
## To get help
310
302
311
303
We have Gitter here: <https://gitter.im/mypy-django/Lobby>
0 commit comments