Tuples should be immutable and safe in C, as well as in Python.
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug report
Bug description:
[Apologies if this sounds a bit like a rant. I'm not blaming anyone. Just because something is the wrong choice now, doesn't mean it wasn't the right choice historically]
Tuples are immutable in Python, but we play all sorts of games in C with tuples, filling them will NULLs, mutating them and reusing them.
We do this in the mistaken belief that it improves performance.
But it doesn't. It makes the code base more complicated and fragile as we need to work around tuples that misbehave and do strange things. Any local performance gain is overwhelmed by slowdowns caused by the extra complexity in tuple code, the garbage collector and a few other places.
So let's fix this.
We need to:
- Provide a new C API
PyTuple_MakePair(). Pairs are by far the most common type of tuple that we play games with. By providing a fast way to create pairs, we can provide an upgrade path for C code that creates tuples in unsafe ways to do so safely and quickly. - Deprecate
PyTuple_New. I don't know when we'll be able to remove it, but we should deprecate it ASAP. - Change
PyTuple_Newto fill the tuple with pointers toNoneinstead ofNULL. This doesn't fix the mutability issue, but it at least means the GC will only see valid objects. (This might break too much code, so we might just have to clearly document that tuples should be fully initialized in one go, before the tuple escapes the function it was created in) - Fix our own code to not use
PyTuple_New()or perform tuple shenanigans. We can't reasonably expect third-party package authors to follow the rules if we don't.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-127758
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 revisando las APIs de C PyTuple_New y PyTuple_MakePair propuestas y, después, inspecciona el PR vinculado gh-127758 para entender el trabajo que ya está en curso. Se considerará terminado cuando se aborden los cambios solicitados relacionados con la seguridad de las tuplas, incluida la transición de la API, el comportamiento de inicialización y la eliminación del uso interno inseguro de tuplas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- c, python
- Área
- backend
- Tipo de issue
- Error
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 25/100