Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix partially analyzed settings module #1162

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy_django_plugin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def get_additional_deps(self, file: MypyFile) -> List[Tuple[int, str, int]]:

# for `get_user_model()`
if self.django_context.settings:
if file.fullname == "django.contrib.auth" or file.fullname in {"django.http", "django.http.request"}:
if file.fullname == "django.contrib.auth":
auth_user_model_name = self.django_context.settings.AUTH_USER_MODEL
try:
auth_user_module = self.django_context.apps_registry.get_model(auth_user_model_name).__module__
Expand Down
25 changes: 25 additions & 0 deletions tests/typecheck/test_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,28 @@
content: |
from pathlib import Path
MEDIA_ROOT = Path()

- case: imported_from_models
disable_cache: true
custom_settings: |
from other import other
AUTH_USER_MODEL = "my_app.MyUser"
INSTALLED_APPS = ["my_app"]
MY_LIST = [1]
main: |
from typing import TYPE_CHECKING
from django.conf import settings
if TYPE_CHECKING:
reveal_type(settings.MY_LIST) # N: Revealed type is "builtins.list[builtins.int]"
files:
- path: my_app/__init__.py
- path: my_app/models.py
content: |
from django.db import models
import main
class MyUser(models.Model):
pass
- path: other.py
content: |
from django_stubs_ext import ValuesQuerySet
other = ()