`hasattr(stream, "buffer") fails with ValueError if buffer is detached
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
- #160467 de @scrieve — cerrado sin fusionar
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Start by reading the linked pull request #160467 and the stream buffer property implementation and related tests it identifies. Reproduce the detached-buffer example in the issue on the affected Python versions, then use the relevant tests to confirm hasattr(stream, "buffer") no longer raises ValueError after detachment.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Bug report
>>> stream = open("example.txt", "w")
>>> hasattr(stream, "buffer")
True
>>> stream.detach()
<_io.BufferedWriter name='example.txt'>
>>> hasattr(stream, "buffer")
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
hasattr(stream, "buffer")
~~~~~~~^^^^^^^^^^^^^^^^^^
ValueError: underlying buffer has been detached
This occurs with Python 3.14.9 and 3.15.1, but not with earlier versions such as 3.14.8 and 3.15.0. Tested both on Linux and on Windows. I consider hasattr failing with an exception pretty bad, especially when using it with standard library objects, and the behavior changing in a bug fix release makes it even worse.
I noticed this when a unit test for our custom isatty utility started to fail (https://github.com/robotframework/robotframework/issues/5825). We have that utility so that we can safely check is a stream connected to console or not. It used to look like this:
def isatty(stream):
# first check if buffer was detached
if hasattr(stream, "buffer") and stream.buffer is None:
return False
if not hasattr(stream, "isatty"):
return False
try:
return stream.isatty()
except ValueError: # Occurs if file is closed.
return False
I already fixed this in our end by simply removing the separate detached buffer check. stream.isatty() raised a ValueError if its buffer is detached, similarly when the stream is closed, and we already handle that. Apparently the separate check was added before handling closed streams and nobody noticed earlier that the check is redundant.
CPython versions tested on:
3.14, 3.15
Operating systems tested on:
Linux, Windows
Linked PRs
- gh-160467
- Lenguaje dominante
- Python
- Estrellas
- 77.7k
- Forks
- 38.3k
- Merge medio
- 13 h 43 min
- PR fusionados (30 d)
- 704
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la 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.
Más de python/cpython
-
topic-socket type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
python/cpython#160561 · 7 comentarios ·
Los mantenedores suelen responder en 1 día
-
tests topic-profiling type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
python/cpython#160334 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
`iso2022_jp_3` encodes U+9B1D but decodes the result as U+9B1CPosiblemente ocupada @kinqsradio la tomó hoy. Abiertoextension-modules type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día
-
Remove unused FVS_* macrosAbiertointerpreter-core type-feature
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
python/cpython#160109 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
extension-modules type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
python/cpython#160001 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de python/cpython
Issues similares
-
area/config comp/tools P2 platform/telegram type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
NousResearch/hermes-agent#145412 ·
Los mantenedores suelen responder en 1 día
-
[oblt-aw][autodoc] Update docs for security org scaffolding and Docs AI menu permission changesPosiblemente ocupada @github-actions la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
Community project: hosted MOSS-Image studio with a visual JSON layout builder (no ComfyUI needed)Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 65/100
OpenMOSS/MOSS-Image#27 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
deepspeedai/DeepSpeed#8925 · 1 comentario ·
Los mantenedores suelen responder en 3 días
-
external integration integration-submission
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
langchain-ai/docs#7077 ·
Los mantenedores suelen responder en 1 día