Repository: typeddjango/django-stubs

Issue:
Error constructing plugin instance of NewSemanalDRFPlugin
# Bug report

When I run mypy with both `django-stubs` and `djangorestframework-stubs` plugins endabled, I have got following error:

```console
Error constructing plugin instance of NewSemanalDRFPlugin

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/nginx/.local/lib/python3.9/site-packages/mypy/__main__.py", line 23, in <module>
    console_entry()
  File "/home/nginx/.local/lib/python3.9/site-packages/mypy/__main__.py", line 11, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "mypy/main.py", line 87, in main
  File "mypy/main.py", line 165, in run_build
  File "mypy/build.py", line 179, in build
  File "mypy/build.py", line 229, in _build
  File "mypy/build.py", line 475, in load_plugins
  File "mypy/build.py", line 453, in load_plugins_from_config
  File "/home/nginx/.local/lib/python3.9/site-packages/mypy_drf_plugin/main.py", line 26, in __init__
    self.django_context = DjangoContext(django_settings_module)
  File "/home/nginx/.local/lib/python3.9/site-packages/mypy_django_plugin/django/context.py", line 96, in __init__
    apps, settings = initialize_django(self.django_settings_module)
  File "/home/nginx/.local/lib/python3.9/site-packages/mypy_django_plugin/django/context.py", line 66, in initialize_django
    assert not hasattr(builtins, "reveal_type")
AssertionError
```

I have got following mypy.ini configuration
```ini
[mypy]
python_version = 3.9
ignore_missing_imports = True
plugins =
    mypy_django_plugin.main,
    mypy_drf_plugin.main

[mypy.plugins.django-stubs]
django_settings_module = "blenderhub.settings.production"
```

This bug may appear only whit asserts enabled in python.

## What's wrong

The `DjangoContext` is inicialized both in `django-stubs` and `djangorestframework-stubs` which runs into failed assertion introduced by changes in `mypy_django_plugin/django/context.py` in https://github.com/typeddjango/django-stubs/commit/a00563cfa42e153a2457bdcc1e21b092e3ee0444.

## How is that should be

If I run mypy with `python -O -m mypy blenderhub/` it works all right.

## System information

- OS: Docker python:3.90-slim
- `python` version: 3.9.6
- `django` version: 3.1.13
- `mypy` version: 0.910
- `django-stubs` version: 1.8.0
- `djangorestframework-stubs` version: 1.4.0



Discussion:
Yeah, we need to remove these `assert`s. Can you, please?

Resolving patch:
diff --git a/mypy_django_plugin/django/context.py b/mypy_django_plugin/django/context.py
--- a/mypy_django_plugin/django/context.py
+++ b/mypy_django_plugin/django/context.py
@@ -64,9 +64,7 @@ def noop_class_getitem(cls, key):
 
         # Define mypy builtins, to not cause NameError during setting up Django.
         # TODO: temporary/unpatch
-        assert not hasattr(builtins, "reveal_type")
         builtins.reveal_type = lambda _: None
-        assert not hasattr(builtins, "reveal_locals")
         builtins.reveal_locals = lambda: None
 
         from django.apps import apps


Test patch: