python / python/cpython

shutil: Inconsistent return types when using pathlib

Aperta
#132,322 3 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

stdlib topic-pathlib type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug report

Bug description:

Using pathlib with shutil usually works, but there are some quirks when it comes to return types. As an example, see the copy function (but other functions are affected as well):

https://github.com/python/cpython/blob/67ded6a4faae29edff8e4f7886978e71ce116e33/Lib/shutil.py#L468-L484

In this case, if a Path object gets passed in as dst, it will be returned unchanged if it is not a directory, but a str will be returned if it is a directory. That's unexpected, the return type should be consistent, probably by always returning a str.

I assume that pathlib support is mostly incidental in shutil, considering that the latter predates the former. shutil should probably be reviewed for proper pathlib support at some point. (See also a few other pathlib/shutil related issues reported here.)

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs
  • gh-132820

Guida per i contributori

Apri la guida per i contributori

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.

Direzione di ricerca

Controlla prima la PR collegata gh-132820, quindi esamina Lib/shutil.py intorno a copy e le altre funzioni relative a pathlib menzionate nel report. Rivedi i test esistenti di shutil e assicurati che le funzioni interessate abbiano tipi restituiti coerenti e documentati, con test che coprano destinazioni Path che sono directory e destinazioni Path che non lo sono.

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

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.