Crash on a type alias to new-style union of unresolved types
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Crash Report
mypy crashes when used with the latest version of Qiskit 2.4.0, released yesterday (2026-04-16).
Both the released mypy 1.20.1 and master version crash.
Note: the Qiskit package is not typed, so I use the option --follow-untyped-imports. mypy does not crash with the previous release of Qiskit, 2.3.1, but crashes with the latest 2.4.0 release.
Traceback
version: 2.0.0+dev.410f9339916d836b10a286adc1dae43d9f12d251
Traceback (most recent call last):
File "/Users/tmartine/micromamba/envs/mypy-bug/bin/mypy", line 6, in <module>
sys.exit(console_entry())
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/__main__.py", line 15, in console_entry
main()
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/main.py", line 143, in main
res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/main.py", line 233, in run_build
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/build.py", line 421, in build
result = build_inner(
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/build.py", line 529, in build_inner
graph = dispatch(sources, manager, stdout, connect_threads)
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/build.py", line 4012, in dispatch
process_graph(graph, manager)
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/build.py", line 4476, in process_graph
done, still_working, results = manager.wait_for_done(graph)
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/build.py", line 1389, in wait_for_done
process_stale_scc(graph, next_scc, self)
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/build.py", line 4650, in process_stale_scc
graph[id].type_check_first_pass()
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/build.py", line 3271, in type_check_first_pass
self.type_checker().check_first_pass(recurse_into_functions=recurse_into_functions)
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/checker.py", line 538, in check_first_pass
self.accept(d)
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/checker.py", line 649, in accept
stmt.accept(self)
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/nodes.py", line 1877, in accept
return visitor.visit_assignment_stmt(self)
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/checker.py", line 3186, in visit_assignment_stmt
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/checker.py", line 3361, in check_assignment
rvalue_type, lvalue_type = self.check_simple_assignment(
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/checker.py", line 4767, in check_simple_assignment
rvalue_type = self.expr_checker.accept(
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/checkexpr.py", line 6178, in accept
typ = self.accept_maybe_cache(node, type_context=type_context)
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/checkexpr.py", line 6213, in accept_maybe_cache
typ = node.accept(self)
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/nodes.py", line 2667, in accept
return visitor.visit_op_expr(self)
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/checkexpr.py", line 3557, in visit_op_expr
return self.accept(e.analyzed)
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/checkexpr.py", line 6180, in accept
typ = node.accept(self) # r-value type, when interpreted as a value expression
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/nodes.py", line 3390, in accept
return visitor.visit_type_alias_expr(self)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/checkexpr.py", line 4962, in visit_type_alias_expr
return self.alias_type_in_runtime_context(alias.node, ctx=alias, alias_definition=True)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/checkexpr.py", line 5019, in alias_type_in_runtime_context
return self.chk.named_generic_type("types.UnionType", item.items)
~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/checker.py", line 7605, in named_generic_type
args = [remove_instance_last_known_values(arg) for arg in args]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/erasetype.py", line 239, in remove_instance_last_known_values
return t.accept(LastKnownValueEraser())
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/mypy/types.py", line 3608, in accept
assert isinstance(visitor, SyntheticTypeVisitor)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
/Users/tmartine/micromamba/envs/mypy-bug/lib/python3.14/site-packages/qiskit/circuit/library/arithmetic/quadratic_form.py:27: note: use --pdb to drop into pdb
To Reproduce
mamba create -n mypy-bug python==3.14 mypy qiskit==2.4.0
echo "import qiskit" > mypy_bug.py
mamba run -n mypy-bug mypy --show-traceback --follow-untyped-imports mypy_bug.py
Your Environment
- Mypy version used: 1.20.1 and
master - Mypy command-line flags:
--show-traceback --follow-untyped-imports - Mypy configuration options from
mypy.ini(and other config files): - Python version used: 3.14
- Operating system and version: macOS 26.4.1 (25E253)
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Esegui la riproduzione mamba fornita con Qiskit 2.4.0 e --follow-untyped-imports. Inizia in mypy/checkexpr.py, in alias_type_in_runtime_context, e segui la chiamata fino a mypy/erasetype.py e all’assertion di SyntheticTypeVisitor. Il lavoro è completato quando la riproduzione non va più in crash e il caso dell’alias di unione non risolto ha una copertura di regressione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 55/100