Skip to content

INTERNAL ERROR with Qiskit 2.4.0 #21263

@thierry-martinez

Description

@thierry-martinez

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)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions