python / python/mypy

Crash on a type alias to new-style union of unresolved types

Abierto
#21,263 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

crash topic-import-cycles topic-pep-604 topic-type-alias
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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)

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Ejecuta la reproducción proporcionada de mamba con Qiskit 2.4.0 y --follow-untyped-imports. Empieza en mypy/checkexpr.py, en alias_type_in_runtime_context, y sigue la llamada hasta mypy/erasetype.py y la aserción de SyntheticTypeVisitor. Se considera terminado cuando la reproducción ya no se bloquea y el caso del alias de unión no resuelto tiene cobertura de regresión.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
devtools
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Tranquilo
Claridad
Bien especificado
Aptitud para principiantes
55/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.