python / python/cpython

shutil: Inconsistent return types when using pathlib

Abierto
#132,322 3 comentarios 3 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

stdlib topic-pathlib type-bug
Lenguaje dominante
Python
Estrellas
77.2k
Forks
36k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comprueba primero el PR vinculado gh-132820 y, después, inspecciona Lib/shutil.py alrededor de copy y las otras funciones relacionadas con pathlib mencionadas en el informe. Revisa las pruebas existentes de shutil y asegúrate de que las funciones afectadas tengan tipos de retorno coherentes y documentados, con pruebas que cubran destinos Path que sean directorios y que no lo sean.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
backend
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.