Repository navigation
"unresolved placeholder type None" on mypy 1.0.0 #14631
Copy link
Copy link
Closed
Labels
Description
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.
import asyncsshOr:
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:
from typing import TypeVar, Callable
T = TypeVar('T', 'A', 'B')
Func = Callable[[], T]With the above snippet it still happens.
Your Environment
- 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
Reactions are currently unavailable
Activity
wjurkowlaniec commentedon Feb 7, 2023
I have the same problem..
hauntsaninja commentedon Feb 7, 2023
Thanks for the report! Confirming the crash and the regression from 0.991
And thank you for the minimal repro here!
Fix crash on deferred value constrained TypeVar
Fix crash on deferred value constrained TypeVar (#14642)
Fix crash on deferred value constrained TypeVar (python#14642)
[backport] Fix crash on deferred value constrained TypeVar (#14642) (#…
jonathanslenders commentedon Feb 10, 2023
@hauntsaninja : Thanks for the quick fix!!
ronf commentedon Feb 12, 2023
I just upgraded to mypy 1.0.0 here and I'm now getting an error running mypy on the AsyncSSH package with the definition of the _ConnectionFactory type that triggered this issue:
The relevant definitions are:
The SSHClientConnection and SSHServerConnection classes are declared later in this module.
The specific error is:
asyncssh/connection.py:272: error: Invalid type argument value for "_ConnectionFactory" [type-var]
Any idea how I avoid this error? It only shows up in this one place, while other similar references to _ConnectionFactory[_Conn] are working fine. For instance, the following doesn't give an error:
My environment:
Tasssadar commentedon Mar 2, 2023
Hello, we are still seeing this error with
mypy==1.0.1:Unfortunately, the code base is large and proprietary, so I can't supply the code. I tried to figure out which exactly causes it, but was unable to narrow it down to anything concrete. Is there anything I can set to have mypy output more details? I tried
-v, but the crash is in the phase where it doesn't really output anything.ronf commentedon Mar 2, 2023
I don't know if it will help or not, but here's how I worked around this problem in AsyncSSH after upgrading to mypy 1.0.0:
ronf/asyncssh@0d49161
Basically, I eliminated a type definition of the form
Callable[[[], T], whereTwas aTypeVarthat could be one of two types. By using theCallabletype directly in places where it was needed rather than assigning it and using that assignment, the problem went away.jindongyang94 commentedon Oct 23, 2024
Hi @Tasssadar , are you able to resolve your issue yet? Just a shot in the dark as I am currently experiencing the same issue and error, perhaps you installed pandas-stubs and it is causing your codebase with pandas to face this issue.
For me, that was the problem and I have raised an issue with pandas-stubs separately. Hope this helps!
Tasssadar commentedon Oct 23, 2024
I haven't seen this in a while, so probably fixed in one of the MyPy updates that arrived in the meantime. But it's definitely not a pandas-stubs issue, this is mypy hard-crashing, that is never the right behavior - at the very least, it must produce some helpful message about what is wrong.