summaryrefslogtreecommitdiff
path: root/assets/outbox/pyright-and-django-stubs.txt
blob: a9fcd908ff2fc32f7bb78cc18940a58c6fbd9b0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
pyright and django-stubs
========================

WHY
---
Emacs is configured to use pyright as the Python LSP server (via lsp-pyright)
instead of pylsp. Pyright has significantly better type inference, especially
for Django's dynamic attributes (model fields, querysets, managers). With
django-stubs, pyright understands the Django ORM well enough to provide
accurate completions and type checking on QuerySets, Model.objects, request
objects, etc.

PYRIGHT (language server - system-wide tool)
--------------------------------------------
Install via pacman, NOT pip:

    sudo pacman -S pyright

Pyright is already in the Arch extra repo. Do not use pip or pipx for this —
pacman keeps it updated with the rest of the system.

DJANGO-STUBS (per-project, in the project venv)
------------------------------------------------
django-stubs provides type stubs for Django so pyright understands Django's
dynamic attributes. Install inside each Django project's virtual environment:

    pip install django-stubs

This must be installed per-project (not globally) because it needs to match
the Django version in use. Also add to requirements-dev.txt or pyproject.toml
so other developers get it automatically.

Also requires a pyrightconfig.json at the project root with:

    {
      "plugins": ["django-stubs"]
    }

Or if using pyright's djangoStubs setting directly:

    {
      "djangoStubs": true
    }

SUMMARY
-------
- pyright:       pacman (system tool, installed once)
- django-stubs:  pip in venv (per Django project)