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

Please consider clarifying use of unsafe in README example

Aperta
#433 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
50/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
numpy, rust
Ambito
documentation

Direzione di ricerca

Inizia con l’esempio di codice PyO3 in README e analizza il breve blocco unsafe e le firme delle funzioni circostanti. Aggiungi una spiegazione concisa della sicurezza e riferimenti alla documentazione pertinente, chiarendo anche perché non viene utilizzata l’alternativa con un array mutabile. Il lavoro è completato quando l’esempio spiega il proprio uso di unsafe senza aggiungere una lunga discussione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Thanks for providing this amazing library!

The code example given in this project's README file demonstrates the use of PyO3. I guess that it should also serve as a pedagogical model of how PyO3 should be used. After all, this is often going to be the first bit of PyO3-using code that prospective users are going to see.

Now that example features a short unsafe block without any explanation. But the usage of unsafe in Rust code means that the safety of the featured block has been carefully verified and the compiler should trust that.

In practice the usage of unsafe is quite often accompanied by a comment that explains why it is safe. This should certainly be the case in pedagogical code. I think that such a comment would be very helpful here.

Perhaps this particular use of unsafe is obvious to seasoned PyO3 users, but it certainly isn't to newbies for whom this code will often be the first contact with PyO3. Here are some question answers that may come up:

  • Why is this particular use of unsafe safe after all?
  • Are there any assumptions without which this would no longer be the case?
  • The first function of the module takes PyReadonlyArrayDyn<'py, f64> arguments. It seems that the second function could similarly take a PyReadwriteArrayDyn<'py, f64> argument (which provides a safe as_array_mut method), but it takes &Bound<'py, PyArrayDyn<f64>> instead. Is this indeed a choice and what is the reason behind it?

I'm not suggesting that a long discussion of this issue should be added to the README. Probably a short comment and a few pointers into the documentation would be enough.

Lingua principale
Rust
Stelle
1.4k
Fork
141
Merge medio
16m
PR unite (30g)
3

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

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 PyO3/rust-numpy

Tutte le issue di PyO3/rust-numpy

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.