jazzband / django-configurations

A helper for organizing Django project settings by relying on well established programming patterns.
https://django-configurations.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.1k stars 143 forks source link

Add `mypy` plugin #340

Open mvandenburgh opened 2 years ago

mvandenburgh commented 2 years ago

Fixes #267. Related issue in the django-stubs repo - https://github.com/typeddjango/django-stubs/issues/417

I've also added a section to the docs describing how to use this.

RJPercival commented 2 years ago

Unfortunately, this won't work well for any settings that have a value of None, {} or [], i.e. settings where their type can't be inferred from their runtime value. For those, you'll get errors like Invalid index type "str" for "dict"; expected type "_KT". A better approach would be to make a mypy plugin that can find the setting definitions on the Configuration subclass that you're using and take the type hints from there. I've written such a plugin and it works well, but haven't had time to open-source it yet. If anyone wants that plugin, let me know here and I'll spend some time open-sourcing it.