stubtest raises an exception when a `classmethod`'s first parameter not named `cls`
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Crash Report
From https://github.com/python/typeshed/pull/10544#discussion_r1368024543
Where networkx's source code has:
class EdgeComponentAuxGraph:
@classmethod
def construct(EdgeComponentAuxGraph, G): ...
Traceback
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 1891, in <module>
sys.exit(main())
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 1887, in main
return test_stubs(parse_options(sys.argv[1:]))
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 1760, in test_stubs
for error in test_module(module):
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 223, in test_module
yield from verify(stub, runtime, [module_name])
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 401, in verify_mypyfile
yield from verify(stub_entry, runtime_entry, object_path + [entry])
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 543, in verify_typeinfo
yield from verify(stub_to_verify, runtime_attr, object_path + [entry])
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 1261, in verify_decorator
func = _resolve_funcitem_from_decorator(stub)
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 1240, in _resolve_funcitem_from_decorator
resulting_func = apply_decorator_to_funcitem(decorator, func)
File "C:\Users\Avasam\AppData\Local\Temp\tmpmhpy63_q\lib\site-packages\mypy\stubtest.py", line 1225, in apply_decorator_to_funcitem
raise StubtestFailure(
__main__.StubtestFailure: unexpected class argument name 'EdgeComponentAuxGraph' in networkx.algorithms.connectivity.edge_kcomponents.EdgeComponentAuxGraph.construct
To Reproduce
(Write what you did to reproduce the crash. Full source code is
appreciated. We also very much appreciate it if you try to narrow the
source down to a small stand-alone example.)
From my experience, in typeshed, changing any classmethod's first parameter of a class that is present at runtime should raise the exception.
For example, in stubs/urllib3/urllib3/fields.pyi, you could change RequestField.from_tuples's cls parameter to anything else (ie: not_cls). Then run python ./tests/stubtest_third_party.py urllib3.
Your Environment
- Mypy version used: mypy 1.7.1 (compiled: yes)
- Mypy command-line flags: (see typeshed)
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.9.13
- Operating system and version: Windows 10 Version 10.0.19045 Build 19045
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
traceback をたどりながら、mypy/stubtest.py の verify_decorator、_resolve_funcitem_from_decorator、apply_decorator_to_funcitem 付近から始めます。urllib3 の例で再現し、tests/stubtest_third_party.py urllib3 を実行します。runtime classmethod の最初のパラメーター名が cls でない場合でも stubtest が例外を発生させなくなり、リグレッションカバレッジが追加されていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools, testing-qa
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 48/100