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
Copy file name to clipboardExpand all lines: README.md
+25-15Lines changed: 25 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,10 @@ Could be run on earlier versions of Django, but expect some missing imports warn
17
17
pip install django-stubs
18
18
```
19
19
20
+
### WARNING: All configuration from pre-1.0.0 versions is dropped, use one below.
21
+
22
+
### WARNING: 1.0.0 breaks `dmypy`, if you need it, stay on the 0.12.x series.
23
+
20
24
To make mypy aware of the plugin, you need to add
21
25
22
26
```
@@ -27,27 +31,33 @@ plugins =
27
31
28
32
in your `mypy.ini` file.
29
33
34
+
Plugin requires Django settings module (what you put into `DJANGO_SETTINGS_MODULE` variable) to be specified inside `mypy.ini` file.
35
+
```
36
+
[mypy]
37
+
strict_optional = True
30
38
31
-
## Configuration
32
-
33
-
In order to specify config file, set `MYPY_DJANGO_CONFIG` environment variable with path to the config file. Default is `./mypy_django.ini`
34
-
35
-
Config file format (.ini):
39
+
; this one is new
40
+
[mypy.plugins.django-stubs]
41
+
django_settings_module = mysettings
36
42
```
37
-
[mypy_django_plugin]
43
+
where `mysettings` is a value of `DJANGO_SETTINGS_MODULE` (with or without quotes)
44
+
45
+
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()`.
38
46
39
-
# specify settings module to use for django.conf.settings, this setting
40
-
# could also be specified with DJANGO_SETTINGS_MODULE environment variable
41
-
# (it also takes priority over config file)
42
-
django_settings = mysettings.local
47
+
In other words, if your `manage.py runserver` crashes, mypy will crash too.
43
48
44
-
# if True, all unknown settings in django.conf.settings will fallback to Any,
45
-
# specify it if your settings are loaded dynamically to avoid false positives
46
-
ignore_missing_settings = True
49
+
## Notes
47
50
48
-
# if True, unknown attributes on Model instances won't produce errors
49
-
ignore_missing_model_attributes = True
51
+
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
50
52
```
53
+
class MyUserManager(models.Manager['MyUser']):
54
+
pass
55
+
class MyUser(models.Model):
56
+
objects = UserManager()
57
+
```
58
+
work, which should make a error messages a bit better.
59
+
60
+
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`.
0 commit comments