Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Rank-typing

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

@jorenham がすでに取り組んでいます。

2025年5月4日 から。

評価

この issue はまだ評価されていません。

説明

is: Tracker topic: shape-typing

Shape-typing is often described as being able to distinguish between axes or their their sizes. But in Python's current type-system, that isn't realistically possible. If you remove the individual axes from a shape, you end up with just a rank, a.k.a. ndim. At runtime it's trivially simple, because it's just an int. But helpfully describing it using static typing is quite the opposite, and is probably the biggest typing-challenge I've ever had to solve.

For a long time, I thought that integer tuples would be the only option we could use for this. But for many situations, that would be very impractical to use, and limited in its expressiveness. I'm not sure if it would have even been worth it.

But I recently figured out an overpowered trick that I've been calling "static embedding", with which I was able to encode the complete set of NEP 50 promotion rules within the scalar types. That made it possible to write a couple of Casts* type-aliases (powered by typing.Protocol), which, when applied to the binary scalar operator methods, reduced __init__.pyi by over 5,000 LOC (!). That made me realize that the underlying "static embedding" principle could also be used for the broadcasting rules, i.e. the main use-case of shape- rank-typing.

And so far, it's looking pretty promising. It may also provide a way to simplify the array-like typing aliases for specific ndim, by associating e.g. Sequence[Sequence[T]] with the 2-d rank-type, Rank2.

This issue is intended as a tracker for the rank-typing progress. See the PR's below for the juicy details:

  • #538
  • #544
  • #545
  • #550
  • #552
  • #559
  • #714

For relevant discussion with additional details, see:

  • numpy/numpy#16544
  • python/typing#513
  • #578
主要言語
Python
スター
79
フォーク
8
PR マージ指標
30日以内にマージされた PR はありません

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

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

はじめの一歩

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

numpy/numtype のほかの issue

numpy/numtype の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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