Commit ff121d5
committed
fix(mypy): Add django.contrib.auth to INSTALLED_APPS for mypy compatibility
Root cause analysis:
- After commit 5867e0c (dev package bump), mypy started failing with an
AssertionError in mypy_django_plugin/transformers/auth.py
- The django-stubs plugin analyzes ALL Django type stubs, including
django.contrib.auth.forms, even if the project doesn't directly use them
- When resolving the _User type alias in auth.forms, the plugin calls
_get_abstract_base_user() which looks up AbstractBaseUser
- This lookup fails when django.contrib.auth is not in INSTALLED_APPS,
causing sym.node to not be a TypeInfo
Why this doesn't affect other projects:
- Most Django projects include django.contrib.auth in INSTALLED_APPS by
default (it's a standard contrib app)
- django-stubs' own test settings include auth in INSTALLED_APPS
- This project had only ["test_app"] in INSTALLED_APPS
The fix:
- Add django.contrib.contenttypes and django.contrib.auth to INSTALLED_APPS
in tests/settings.py (contenttypes is a dependency of auth)
- Add mypy override for test_app to ignore no-untyped-call errors from
django-extensions' AutoSlugField
Verified:
- mypy now passes: "Success: no issues found in 14 source files"
- All 6 tests still pass1 parent 991d80c commit ff121d5
2 files changed
+11
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
144 | 150 | | |
145 | 151 | | |
146 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
15 | 19 | | |
16 | 20 | | |
0 commit comments