From 66d5045ed95ee9e0b63bc50c335a3388dbd28258 Mon Sep 17 00:00:00 2001 From: Bob Whitelock Date: Thu, 20 May 2021 17:24:33 +0100 Subject: [PATCH] Document limitation with `django_stubs_ext.monkeypatch()` (#619) This monkey patching will only work when using Python 3.7+, which introduced the `__class_getitem__` magic method. This tripped me up for a while as I was on Python 3.6 and wondered why the monkey patching was not working, therefore documenting this to point this out to future readers. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a149c53..053b31c 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,8 @@ import django_stubs_ext django_stubs_ext.monkeypatch() ``` +Note: This monkey patching approach will only work when using Python 3.7 and higher, when the `__class_getitem__` magic method was introduced. + 2. You can use strings instead: `'QuerySet[MyModel]'` and `'Manager[MyModel]'`, this way it will work as a type for `mypy` and as a regular `str` in runtime. ### How can I create a HttpRequest that's guaranteed to have an authenticated user?