Skip to content

Commit b939bc9

Browse files
authored
Improves README with new example repo, python version matrix (#195)
1 parent 02bdf5b commit b939bc9

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

README.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,26 @@
88

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

11-
Supports Python 3.6/3.7, and Django 2.1/2.2.
12-
1311
Could be run on earlier versions of Django, but expect some missing imports warnings.
1412

13+
1514
## Installation
1615

1716
```bash
1817
pip install django-stubs
1918
```
2019

21-
## Mypy compatibility
2220

23-
| django-stubs | mypy version | django version |
24-
| ------------ | ---- | ---- |
25-
| 1.2.0 | 0.730 | 2.2.x
26-
| 1.1.0 | 0.720 | 2.2.x
27-
| 0.12.x | old semantic analyzer (<0.711), dmypy support | 2.1.x
21+
## Mypy compatibility
2822

23+
| django-stubs | mypy version | django version | python version
24+
| ------------ | ---- | ---- | ---- |
25+
| 1.2.0 | 0.730 | 2.2.x | ^3.6
26+
| 1.1.0 | 0.720 | 2.2.x | ^3.6
27+
| 0.12.x | old semantic analyzer (<0.711), dmypy support | 2.1.x | ^3.6
2928

30-
### WARNING: All configuration from pre-1.0.0 versions is dropped, use one below.
3129

32-
### WARNING: 1.0.0 breaks `dmypy`, if you need it, stay on the 0.12.x series.
30+
## Configuration
3331

3432
To make mypy aware of the plugin, you need to add
3533

@@ -39,37 +37,43 @@ plugins =
3937
mypy_django_plugin.main
4038
```
4139

42-
in your `mypy.ini` file.
40+
in your `mypy.ini` or `setup.cfg` [file](https://mypy.readthedocs.io/en/latest/config_file.html).
4341

44-
Plugin requires Django settings module (what you put into `DJANGO_SETTINGS_MODULE` variable) to be specified inside `mypy.ini` file.
42+
Plugin also requires Django settings module (what you put into `DJANGO_SETTINGS_MODULE` variable) to be specified.
4543

4644
```ini
4745
[mypy]
4846
strict_optional = True
4947

50-
; this one is new
48+
# This one is new:
5149
[mypy.plugins.django-stubs]
5250
django_settings_module = mysettings
5351
```
5452

55-
where `mysettings` is a value of `DJANGO_SETTINGS_MODULE` (with or without quotes)
53+
Where `mysettings` is a value of `DJANGO_SETTINGS_MODULE` (with or without quotes)
5654

57-
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.:
58-
```
55+
You might also need to explicitly tweak your `PYTHONPATH` the very same way `django` does it internally in case you have troubles with mypy / django plugin not finding your settings module. Try adding the root path of your project to your `PYTHONPATH` environment variable like so:
56+
57+
```bash
5958
PYTHONPATH=${PYTHONPATH}:${PWD}
6059
```
6160

62-
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()`.
61+
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()`.
6362

6463
In other words, if your `manage.py runserver` crashes, mypy will crash too.
6564

65+
This fully working [typed boilerplate](https://github.com/wemake-services/wemake-django-template) can serve you as an example.
66+
67+
6668
## Notes
6769

68-
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
70+
Type implementation monkey-patches Django to add `__class_getitem__` to the `Manager` class.
71+
If you would use Python3.7 and do that too in your code, you can make things like
6972

7073
```python
7174
class MyUserManager(models.Manager['MyUser']):
7275
pass
76+
7377
class MyUser(models.Model):
7478
objects = UserManager()
7579
```
@@ -78,6 +82,7 @@ work, which should make a error messages a bit better.
7882

7983
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`.
8084

85+
8186
## To get help
8287

8388
We have Gitter here: <https://gitter.im/mypy-django/Lobby>

0 commit comments

Comments
 (0)