python / python/cpython

Make the capability of getting the source of interactive code public

Abierto
#133,853 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

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

Descripción

Feature or enhancement

Proposal:

In #117500, we create a nice mechanism to register and retrieve the source code of an arbitrary code object. It was a bug fix so we want to keep it as private as possible - it was for PyREPL usage only. However, we did put effort into the design so it can be used in a wider range in the future, and now is the future!

We just passed beta freeze so we have enough time to make it a new feature. The code and mechanism is really simple, it's just about documentation (and whether we want to merge some interfaces).

There are two orthogonal areas I want to bring into discussion, for each I have two proposals:

  1. How do we want the interface
    • Keep it as it is, meaning the user needs to explicitly register and retrieve source code from a complete separate pair of interfaces.
    • Combine getlines and _getline_from_code, making code an optional argument to getlines - take the path when the optional code object is passed in.
  2. How public do we want it to be
    • Make it public to all users.
    • Make it public internally so at least inspect and pdb can use it. (we don't document it, but we keep inspect.getsourcelines work)

In either combination, we have the full backwards compatibility - nothing will be broken. It's more about how much maintenance effort we want to put in and how easy we want the user to use the feature.

An obvious example usage is that, if you want to debug some interactive code, either through pdb.run(), or debug command in pdb. You don't have the source code symbols now, even though it's fully available. With this capability, we can make pdb.run() work nicely with string source code.

cc: @pablogsal

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

https://github.com/python/cpython/pull/117500

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

Comienza con PR #117500 y revisa el mecanismo existente para registrar y recuperar código fuente interactivo. Compara las interfaces propuestas getlines/_getline_from_code y considera cómo las usarían inspect y pdb. Se considera terminado cuando se haya elegido la interfaz y la política de visibilidad pública, se haya documentado la funcionalidad si corresponde y se haya definido el comportamiento esperado de pdb.run() o de la depuración.

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

Evaluación

Stack tecnológico
python
Área
devtools
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.