Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

settings: Hide django_stubs_ext from mypy.

Anders Kaseorg73116f78a57d
diff --git a/zproject/settings.py b/zproject/settings.py
index 42d9d797975..2d413b785ec 100644
--- a/zproject/settings.py
+++ b/zproject/settings.py
@@ -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