This project is open source and community driven. As such we encourage code contributions of all kinds. Some areas you can contribute in:
- Improve the stubs
- Sync stubs with the latest version of the DRF
- Improve plugin code and extend its capabilities
- Write tests
- Update dependencies
- Fix and remove things from our
scripts/stubtest/allowlist_todo.txt
Type stubs in .pyi files should follow
coding conventions from typeshed project.
If you want to start working on this project, you will need to get familiar with python typings. The Mypy documentation offers an excellent resource for this, as well as the python official documentation:
Additionally, the following resources might be useful:
- How to write custom mypy plugins
- Typechecking Django and DRF guide
- Testing mypy stubs, plugins, and types guide
- Awesome Python Typing list
As a first step you will need to fork this repository and clone your fork locally. In order to be able to continously sync your fork with the origin repository's master branch, you will need to set up an upstream master. To do so follow this official github guide.
We use uv to manage our dev dependencies. To install it, see their installation guide
Once it's done, simply run the following command to automatically setup a virtual environment and install dev dependencies:
uv sync
source .venv/bin/activateFinally, install the pre-commit hooks:
pre-commit installWe use mypy, pytest, ruff, and black for quality control. All tools except pytest are executed using pre-commit when you make a commit.
To ensure there are not formatting or typing issues in the entire repository you can run:
pre-commit run --all-filesNOTE: This command will not only lint but also modify files - so make sure to commit whatever changes you've made before hand. You can also run pre-commit per file or for a specific path, simply replace "--all-files" with a target (see this guide for more info).
To execute the unit tests, simply run:
pytestRun bash ./scripts/stubtest.sh to test that stubs and sources are in-line.
We have two special files to allow errors:
scripts/stubtest/allowlist.txtwhere we store things that we really don't care about: hacks, DRF internal utility modules, things that are handled by our plugin, things that are not representable by type system, etcscripts/stubtest/allowlist_todo.txtwhere we store all errors there are right now. Basically, this is a TODO list: we need to work through this list and fix things (or move entries to realallowlist.txt). In the end, ideally we can remove this file
You might also want to disable incremental mode while working on stubtest changes.
This mode leads to several known problems (stubs do not show up or have strange errors).
The workflow for contributions is fairly simple:
- fork and setup the repository as in the previous step.
- create a local branch.
- make whatever changes you want to contribute.
- ensure your contribution does not introduce linting issues or breaks the tests by linting and testing the code.
- make a pull request with an adequate description.
-
Open a pull request that updates
pyproject.toml(anyone can open this PR, not just maintainers):-
Increase
version =value within[project]section. Version numbermajor.minor.patchis formed as follows:major.minorversion must match newest supporteddjangorestframeworkrelease.patchis sequentially increasing for each stubs release. Reset to0ifmajor.minorwas updated. -
Under
dependencies =, update thedjango-stubs>=version to point to latestdjango-stubsrelease. -
Update lockfile, run:
uv lock -
Use pull request title "Version x.y.z release" by convention.
-
-
Ensure the CI succeeds. A maintainer must merge this PR. If it's just a verison bump, no need to wait for a second maintainer's approval.
-
Maintainers need to сreate a new GitHub release:
- Under "Choose a tag" enter the new version number. Do NOT use
vprefix. - Click "Generate release notes".
- Delete all release notes lines containing
by @pre-commit-ciorby @renovate, as these are irrelevant for our users.
- Under "Choose a tag" enter the new version number. Do NOT use
-
Once you feel brave enough, click "Publish release".
-
Check that the release workflow succeeds.