Using a stack to implement literal_eval can avoid RecursionError.
I realized that this error was caused by the C implementation, not Python, so this approach was not effective in avoiding the error.
Related to a closed issue #75934.
The tests are copied from the CPython main branch, retaining only those related to ast.literal_eval. To run the tests, use the following command:
pytestTo run the benchmark, use the following command:
python benchmark.pyBelow are the benchmark results comparing ast.literal_eval and stack_literal_eval, conducted on an Intel(R) Core(TM) Ultra 9 185H using Python 3.12.6 release.
For detailed timings, refer to the benchmark results.
