settings: Hide django_stubs_ext from mypy.

Fixes an import cycle that breaks mypy inference with django-stubs:

zproject.settings → django_stubs_ext → django_stubs_ext.patch →
django.contrib.admin.options → django.contrib.contenttypes.models →
confirmation.models → django.conf → zproject.settings.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-04-17 13:56:57 -07:00 committed by Tim Abbott
parent 72aeaf8d52
commit 73116f78a5
1 changed files with 10 additions and 2 deletions

View File

@ -15,13 +15,21 @@
# See https://zulip.readthedocs.io/en/latest/subsystems/settings.html for more information
#
########################################################################
import django_stubs_ext
from typing import TYPE_CHECKING
# Monkey-patch certain types that are declared as generic types
# generic in django-stubs, but not (yet) as generic types in Django
# itself. This is necessary to ensure type references like
# django.db.models.Lookup[int] work correctly at runtime.
django_stubs_ext.monkeypatch()
#
# Hide this from mypy to avoid creating stupid cycles like
# zproject.settings → django_stubs_ext → django_stubs_ext.patch →
# django.contrib.admin.options → django.contrib.contenttypes.models →
# confirmation.models → django.conf → zproject.settings.
if not TYPE_CHECKING:
import django_stubs_ext
django_stubs_ext.monkeypatch()
from .configured_settings import * # noqa: F403 isort: skip
from .computed_settings import * # noqa: F403 isort: skip