Repository: python/mypy

Issue:
Error analyzing spacy
**Bug Report**

`mypy` hangs and (after a long time) report an error trying to analyze code using [spacy](https://spacy.io/)

**To Reproduce**

I'm using latest versions of spacy and mypy. Analyzing in strict mode raise an AssertionError inside mypy

```bat
> type foo.py
from spacy import load
> type mypy.ini
[mypy]
strict = True
> mypy foo.py
Traceback (most recent call last):
  File "c:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\vito.detullio\Desktop\DELME\venv\Scripts\mypy.exe\__main__.py", line 7, in <module>
  File "c:\users\vito.detullio\desktop\delme\venv\lib\site-packages\mypy\__main__.py", line 11, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "mypy\main.py", line 90, in main
  File "mypy\build.py", line 179, in build
  File "mypy\build.py", line 253, in _build
  File "mypy\build.py", line 2638, in dispatch
  File "mypy\build.py", line 2962, in process_graph
  File "mypy\build.py", line 3079, in process_stale_scc
  File "mypy\build.py", line 2251, in write_cache
  File "mypy\build.py", line 1461, in write_cache
  File "mypy\nodes.py", line 313, in serialize
  File "mypy\nodes.py", line 3140, in serialize
  File "mypy\nodes.py", line 3076, in serialize
AssertionError
```

I'm on windows 10 (20H2), using python  and this is my setup:
```bat
> python --version
Python 3.9.1
> python -mpip freeze
blis==0.7.4
catalogue==2.0.4
certifi==2020.12.5
chardet==4.0.0
click==7.1.2
cymem==2.0.5
en-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.0.0/en_core_web_sm-3.0.0-py3-none-any.whl
idna==2.10
Jinja2==3.0.1
MarkupSafe==2.0.1
murmurhash==1.0.5
mypy==0.812
mypy-extensions==0.4.3
numpy==1.20.3
packaging==20.9
pathy==0.5.2
preshed==3.0.5
pydantic==1.7.4
pyparsing==2.4.7
requests==2.25.1
smart-open==3.0.0
spacy==3.0.6
spacy-legacy==3.0.5
srsly==2.4.1
thinc==8.0.3
tqdm==4.61.0
typed-ast==1.4.3
typer==0.3.2
typing-extensions==3.10.0.0
urllib3==1.26.5
wasabi==0.8.2
```

`mypy foo.py` should return "`Success: no issues found in 1 source file`" as espected from the content of the file



Discussion:
@ZeeD Running this myself, (with some tweaked logging in my local mypy), the issue was because mypy was having issues resolving `spacy.ml.models.multi_task.Doc`. Looking into it in your code base, I do see some imports in `multi_task.py` around `Doc` to avoid circular references.

I was able to resolve it within your code by changing to the two imports of `Doc` from `from ...tokens import Doc` to `from ...tokens.doc import Doc`.

As well I'll submit a PR to mypy to help these become easier to find later.  

Resolving patch:
diff --git a/mypy/nodes.py b/mypy/nodes.py
--- a/mypy/nodes.py
+++ b/mypy/nodes.py
@@ -3080,7 +3080,9 @@ def serialize(self, prefix: str, name: str) -> JsonDict:
                         and fullname != prefix + '.' + name
                         and not (isinstance(self.node, Var)
                                  and self.node.from_module_getattr)):
-                    assert not isinstance(self.node, PlaceholderNode)
+                    assert not isinstance(self.node, PlaceholderNode), (
+                        'Definition of {} is unexpectedly incomplete'.format(fullname)
+                    )
                     data['cross_ref'] = fullname
                     return data
             data['node'] = self.node.serialize()


Test patch: