From 73116f78a57d416f893ef50086b18a312ec3dfa4 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 17 Apr 2024 13:56:57 -0700 Subject: [PATCH] settings: Hide django_stubs_ext from mypy. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- zproject/settings.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/zproject/settings.py b/zproject/settings.py index 42d9d79797..2d413b785e 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