python / python/mypy

Option to remove unsupported annotations from `numpy.ndarray` and `List` in stubgen

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

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

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

説明

Feature

Command-line arguments for stubgen that when enabled will remove unsupported annotations from numpy.ndarray and List
like numpy.ndarray[numpy.float32[3,1]] and List[float[3]] which pybind11 outputs.

FYI: This feature has been implemented for numpy.ndarray in pybind11-stubgen.

Pitch

The stubs generated from extensions made with pybind11 using mypy.stubs are invalid when Eigen types or std::array are used in the interface.

As an example, this output from stubgen,

    def as_numpy(self) -> numpy.ndarray[numpy.float32[3,1]]: ...

will give the following errors when used together with Mypy:

error: Bad number of arguments for type alias, expected: 0, given: 2
error: "ndarray" expects 2 type arguments, but 1 given
error: Invalid type: try using Literal[2] instead?
error: Invalid type: try using Literal[1] instead?

And this

def split(axis_aligned_bounding_box: AxisAlignedBoundingBox, max_extents: List[float[3]]) -> List[AxisAlignedBoundingBox]: ...

will give these errors:

error: "float" expects no type arguments, but 1 given
error: Invalid type: try using Literal[3] instead?

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

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

はじめの一歩

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

調査の方向性

stubgen のコマンドラインエントリポイントから開始し、numpy.ndarray[...] や List[...] などのアノテーションがどのように出力されるかを追跡します。サポートされていないアノテーションを削除するオプションを追加し、生成されたスタブで説明されている mypy エラーが発生しなくなることを確認します。

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

評価

技術スタック
numpy, python
領域
cli, devtools, tooling
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

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

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