python / python/mypy

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

オープン
#21,263 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

crash topic-import-cycles topic-pep-604 topic-type-alias
主要言語
Python
スター
20.6k
フォーク
3.3k
平均マージ
1日 18時間
マージ済み PR(30日)
54

説明

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)

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供されている mamba の再現手順を、Qiskit 2.4.0 と --follow-untyped-imports を使って実行します。mypy/checkexpr.py の alias_type_in_runtime_context から開始し、呼び出しを mypy/erasetype.py と SyntheticTypeVisitor の assertion まで追ってください。再現手順がクラッシュしなくなり、未解決の union alias のケースに回帰テストのカバレッジが追加されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
明確に書かれている
初心者へのやさしさ
55/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。