Passing wrong number of arguments to generic produces runtime errors

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

まず、トレースバックに示されている typing.py のパスを通じて、報告されたジェネリックパラメーターの失敗を再現し、次に typing_extensions.py の対応する検証と比較します。ジェネリック引数の数が正しくない場合の意図された動作が確立され、正しい runtime typing の使用を壊すことなく回帰テストでカバーされれば、この問題は解決です。

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

説明

stdlib topic-typing type-feature

In pypa/hatch#2437, we see a change to a generic type, adding an extra parameter, causing a run-time failure, and since this was used in a build plugin, it cause a build failure and my package to fail to install.

pdm.exceptions.BuildError: Build backend raised error: Showing the last 10 lines of the build output:
    class GitInfoBuildHook(BuildHookInterface[Any]):
                           ~~~~~~~~~~~~~~~~~~^^^^^
  File "/usr/lib/python3.12/typing.py", line 398, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/typing.py", line 1083, in _generic_class_getitem
    _check_generic(cls, params, len(cls.__parameters__))
  File "/tmp/pdm-build-env-4xoutxun-shared/lib/python3.12/site-packages/typing_extensions.py", line 3274, in _check_generic
    raise TypeError(f"Too {'many' if alen > elen else 'few'} arguments"
TypeError: Too few arguments for <class 'hatchling.builders.hooks.plugin.interface.BuildHookInterface'>; actual 1, expected at least 2

I find this behavior fairly surprising; I would only expect type errors in an annotation to cause errors when doing typechecking, not runtime errors like this.

主要言語
Python
スター
77.2k
フォーク
36k
平均マージ
1日 9時間
マージ済み PR(30日)
558

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

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

はじめの一歩

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

python/cpython のほかの issue

python/cpython の issue をすべて見る

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

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