Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Rank-typing

Aperta
#539 2 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@jorenham ci sta già lavorando.

Dal 4/5/2025.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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
Lingua principale
Python
Stelle
79
Fork
8
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di numpy/numtype

Tutte le issue di numpy/numtype

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.