Repository: python/mypy

Issue:
"unresolved placeholder type None" on mypy 1.0.0
**Bug Report**

There is a bug that makes it impossible to typecheck any Python application/library that has an import of the asyncssh package. However, typechecking asyncssh directly doesn't result in this bug. (See below, for a sort of reproducer).

The error looks like this:

```
Traceback (most recent call last):
  File "/home/jonathan/.pyenv/versions/env/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/main.py", line 95, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/main.py", line 174, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/build.py", line 194, in build
    result = _build(
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/build.py", line 277, in _build
    graph = dispatch(sources, manager, stdout)
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/build.py", line 2923, in dispatch
    process_graph(graph, manager)
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/build.py", line 3320, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/build.py", line 3443, in process_stale_scc
    graph[id].write_cache()
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/build.py", line 2504, in write_cache
    new_interface_hash, self.meta = write_cache(
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/build.py", line 1574, in write_cache
    data = tree.serialize()
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/nodes.py", line 377, in serialize
    "names": self.names.serialize(self._fullname),
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/nodes.py", line 3841, in serialize
    data[key] = value.serialize(fullname, key)
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/nodes.py", line 3778, in serialize
    data["node"] = self.node.serialize()
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/nodes.py", line 3514, in serialize
    "target": self.target.serialize(),
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/types.py", line 2072, in serialize
    "ret_type": self.ret_type.serialize(),
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/types.py", line 605, in serialize
    "values": [v.serialize() for v in self.values],
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/types.py", line 605, in <listcomp>
    "values": [v.serialize() for v in self.values],
  File "/home/jonathan/.pyenv/versions/3.9.13/envs/env/lib/python3.9/site-packages/mypy/types.py", line 2876, in serialize
    assert False, f"Internal error: unresolved placeholder type {self.fullname}"
AssertionError: Internal error: unresolved placeholder type None
```

**To Reproduce**

Install `asyncssh`, then create a Python file with only this import and typecheck that file.
```python
import asyncssh
```
Or:
```sh
mypy -c 'import asyncssh'
```

I tried to reduce the code surface as much as possible. Removing every file within asyncssh, except `py.typed` and `__init__.py`, and then write the following in `__init__.py`:

```python
from typing import TypeVar, Callable
T = TypeVar('T', 'A', 'B')
Func = Callable[[], T]
```
With the above snippet it still happens.

**Your Environment**

<!-- Include as many relevant details about the environment you experienced the bug in -->

- Mypy version used: 1.0.0
- Mypy command-line flags:  `--strict`
- Mypy configuration options from `mypy.ini` (and other config files): /
- Python version used: 3.9.13


cc: @ronf


Discussion:
I have the same problem..
Thanks for the report! Confirming the crash and the regression from 0.991

And thank you for the minimal repro here!

Resolving patch:
diff --git a/mypy/types.py b/mypy/types.py
--- a/mypy/types.py
+++ b/mypy/types.py
@@ -590,12 +590,16 @@ def accept(self, visitor: TypeVisitor[T]) -> T:
         return visitor.visit_type_var(self)
 
     def __hash__(self) -> int:
-        return hash((self.id, self.upper_bound))
+        return hash((self.id, self.upper_bound, tuple(self.values)))
 
     def __eq__(self, other: object) -> bool:
         if not isinstance(other, TypeVarType):
             return NotImplemented
-        return self.id == other.id and self.upper_bound == other.upper_bound
+        return (
+            self.id == other.id
+            and self.upper_bound == other.upper_bound
+            and self.values == other.values
+        )
 
     def serialize(self) -> JsonDict:
         assert not self.id.is_meta_var()


Test patch:
diff --git a/test-data/unit/check-typevar-values.test b/test-data/unit/check-typevar-values.test
--- a/test-data/unit/check-typevar-values.test
+++ b/test-data/unit/check-typevar-values.test
@@ -702,3 +702,12 @@ class Indexable:
 
 [builtins fixtures/tuple.pyi]
 [builtins fixtures/classmethod.pyi]
+
+[case testTypeVarWithValueDeferral]
+from typing import TypeVar, Callable
+
+T = TypeVar("T", "A", "B")
+Func = Callable[[], T]
+
+class A: ...
+class B: ...