python / python/mypy

Stubtest crashes if an `@overload` is decorated

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

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

crash topic-stubtest
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

Crash Report

I tried running stubtest on the numpy codebase using the compiled mypy 1.18.2 version + the patch from #20063. This triggered an assertion failure in hypothesis.extra.numpy.arrays (huh?). The relevant code contains code like

@overload
@defines_strategy(force_reusable_values=True)
def arrays(
   # --snip--

which I believe is what is triggering this asserion to fail. See HypothesisWorks/hypothesis#4564 for the relevant code.

Traceback

Traceback (most recent call last):
  File "/home/joren/Workspace/numpy/.venv/bin/stubtest", line 10, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/joren/Workspace/numpy/.venv/lib/python3.14/site-packages/mypy/stubtest.py", line 2448, in main
    return test_stubs(parse_options(sys.argv[1:]))
  File "/home/joren/Workspace/numpy/.venv/lib/python3.14/site-packages/mypy/stubtest.py", line 2296, in test_stubs
    for error in test_module(module):
                 ~~~~~~~~~~~^^^^^^^^
  File "/home/joren/Workspace/numpy/.venv/lib/python3.14/site-packages/mypy/stubtest.py", line 257, in test_module
    yield from verify(stub, runtime, [module_name])
  File "/home/joren/Workspace/numpy/.venv/lib/python3.14/site-packages/mypy/stubtest.py", line 436, in verify_mypyfile
    yield from verify(stub_entry, runtime_entry, object_path + [entry])
  File "/home/joren/Workspace/numpy/.venv/lib/python3.14/site-packages/mypy/stubtest.py", line 1347, in verify_overloadedfuncdef
    stub_sig = Signature.from_overloadedfuncdef(stub)
  File "/home/joren/Workspace/numpy/.venv/lib/python3.14/site-packages/mypy/stubtest.py", line 971, in from_overloadedfuncdef
    assert func is not None, f"Failed to resolve decorated overload of {stub.fullname!r}"
           ^^^^^^^^^^^^^^^^
AssertionError: Failed to resolve decorated overload of 'hypothesis.extra.numpy.arrays'

To Reproduce

  • clone https://github.com/numpy/numpy
  • uv venv .venv
  • source .venv/bin/activate
  • uv pip install -r requirements/build_requirements.txt -r requirements/test_requirements.txt
  • spin build
  • create mypy.ini:
    [mypy]
    ignore_errors = True
    
  • create allowlist.txt:
    numpy\._typing.*
    numpy\.typing\.mypy_plugin
    numpy\.conftest.*
    numpy\.random\._generator\.__test__
    numpy(\.\w+)?\.tests.*
    numpy\._core\.cversions
    numpy\.f2py\.__main__
    numpy\.distutils.*
    numpy\.f2py\._backends\._distutils
    numpy\._build_utils.*
    numpy\._pyinstaller.*
    
  • stubtest --mypy-config-file=mypy.ini --allowlist=allowlist.txt --concise --tb numpy

Your Environment

  • Mypy version used: 1.18.2 (compiled: yes)
  • Mypy command-line flags: see above
  • Mypy configuration options from mypy.ini (and other config files): see above
  • Python version used: 3.14.0
  • Operating system and version: Ubuntu 22.04

BTW, adding hypothesis.* to the allowlist doesn't seem to help.

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

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

はじめの一歩

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

調査の方向性

mypy/stubtest.py の Signature.from_overloadedfuncdef と verify_overloadedfuncdef から始め、traceback を使ってデコレートされた @overload 関数がどのように解決されるかを追跡します。提供されている NumPy のセットアップと stubtest コマンドで再現します。このデコレートされた overload が assertion failure を引き起こさなくなれば完了です。

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

評価

技術スタック
python
領域
testing-qa, tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
52/100

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

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