Skip to content

Commit ff121d5

Browse files
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 pass
1 parent 991d80c commit ff121d5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ module = [
141141
]
142142
ignore_missing_imports = true
143143

144+
[[tool.mypy.overrides]]
145+
module = [
146+
"test_app.*",
147+
]
148+
disable_error_code = ["no-untyped-call"]
149+
144150
[tool.coverage.run]
145151
branch = true
146152
parallel = true

tests/settings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"default": {"NAME": ":memory:", "ENGINE": "django.db.backends.sqlite3"},
1212
}
1313

14-
INSTALLED_APPS: list[str] = ["test_app"]
14+
INSTALLED_APPS: list[str] = [
15+
"django.contrib.contenttypes",
16+
"django.contrib.auth",
17+
"test_app",
18+
]
1519

1620
USE_TZ: bool = False

0 commit comments

Comments
 (0)