Incorrect code collapse while prompting where the error is.
Nadie ha tomado este issue todavía.
- 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:
Read the following code:
# incorrect_collapse.py
def fib(number: int) -> int:
assert number > 0
if number == 1:
return 1
return fib(number - 1) + fib(number - 2) # Notice here
print(fib(2))
There is a mistake in the code above, so if you try to run it, you will get the following traceback:
PC-Killer@ArchLinuxPC ~/p/bugs> python incorrect_collapse.py
Traceback (most recent call last):
File "/home/PC-Killer/python_work/bugs/incorrect_collapse.py", line 9, in <module>
print(fib(2))
~~~^^^
File "/home/PC-Killer/python_work/bugs/incorrect_collapse.py", line 6, in fib
return fib(number - 1) + fib(number - 2) # Notice here
~~~^^^^^^^^^^^^
File "/home/PC-Killer/python_work/bugs/incorrect_collapse.py", line 2, in fib
assert number > 0
^^^^^^^^^^
AssertionError
Notice that the error happened while running the code fib(number - 2).
However, if the number is 5, the duplicate code will be automatically collapsed:
# incorrect_collapse.py
def fib(number: int) -> int:
assert number > 0
if number == 1:
return 1
return fib(number - 1) + fib(number - 2) # Notice here
print(fib(5))
PC-Killer@ArchLinuxPC ~/p/bugs [1]> python incorrect_collapse.py
Traceback (most recent call last):
File "/home/PC-Killer/python_work/bugs/incorrect_collapse.py", line 9, in <module>
print(fib(5))
~~~^^^
File "/home/PC-Killer/python_work/bugs/incorrect_collapse.py", line 6, in fib
return fib(number - 1) + fib(number - 2) # Notice here
~~~^^^^^^^^^^^^
File "/home/PC-Killer/python_work/bugs/incorrect_collapse.py", line 6, in fib
return fib(number - 1) + fib(number - 2) # Notice here
~~~^^^^^^^^^^^^
File "/home/PC-Killer/python_work/bugs/incorrect_collapse.py", line 6, in fib
return fib(number - 1) + fib(number - 2) # Notice here
~~~^^^^^^^^^^^^
[Previous line repeated 1 more time]
File "/home/PC-Killer/python_work/bugs/incorrect_collapse.py", line 2, in fib
assert number > 0
^^^^^^^^^^
AssertionError
The error happened in fib(number - 2). However, in the traceback above, I can only suppose the error happened while running fib(number - 1), which increases the time to find where the real bug is.
CPython versions tested on:
3.13, 3.14
Operating systems tested on:
Linux
Linked PRs
- gh-129973
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
Empieza reproduciendo el comportamiento de colapso del traceback con los dos ejemplos de Fibonacci del issue en CPython 3.13 o 3.14, y después inspecciona los puntos de entrada del formateo del traceback y del colapso de frames. Compara la salida colapsada con el traceback sin recortar y el PR enlazado gh-129973; se considera terminado cuando la expresión que falla siga siendo distinguible después de colapsar los frames repetidos.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- developer-experience
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 20/100