`tarfile.TarFile` has several missing overloads
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 5.1k
- Forks
- 2.1k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 82
Descripción
Right now TarFile.__init__ is defined as: https://github.com/python/typeshed/blob/c7e29eccd9759411c0f46580e20727038668b320/stdlib/tarfile.pyi#L128-L132
Which is not exactly right, because there's a case when name and fileobj are both None at the same time. And this will lead to runtime errors:
>>> import tarfile
>>> tarfile.TarFile(None, fileobj=None)
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
tarfile.TarFile(None, fileobj=None)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
File "/Users/sobolev/Desktop/cpython/Lib/tarfile.py", line 1729, in __init__
fileobj = bltn_open(name, self._mode)
TypeError: expected str, bytes or os.PathLike object, not NoneType
Right now mypy does not raise any errors for this broken case: https://mypy-play.net/?mypy=latest&python=3.12&gist=7452d274249fafba1f8a16565d5486c6
We need either name or fileobj, they can be both None at the same time. So, we need to add overloads.
There are several other methods that needs to be updated like open and taropen, maybe others.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con stdlib/tarfile.pyi alrededor de las líneas 128-132 y revisa las firmas de TarFile.init, open y taropen. Reproduce la llamada None/None con mypy usando el ejemplo del playground enlazado y, después, comprueba que las sobrecargas representan las combinaciones válidas de name/fileobj y diagnostica el caso no válido.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- devtools
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 48/100