Document how import chains are affected by `sys.setrecursionlimit`
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
While working on a very large Python codebase, I ran into some undocumented behaviour.
A chain of imports (i.e. one module imports another, which imports another, which imports another) will cause a RecursionError to be raised if the Python recursion limit is not high enough. (Note, there is no recursion involved.)
Longer chains of imports can be enabled by increasing the recursion limit. But the limit has no effect beyond a certain point (around 10,000). (I believe this is due to Py_C_RECURSION_LIMIT, mentioned in by Serhiy Storchaka.)
A workaround is available: you can import the modules in a different order.
I've created a repository with more analysis and scripts to reproduce the problem. I also started a Discuss topic on the subject.
From what I understand, this is a complex problem that is unlikely to be fixed. But I think it would be helpful to document this, probably in the docs for sys.setrecursionlimit.
I would be happy to try to do a pull request, assuming the core team agree that it should be added.
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece pela documentação de sys.setrecursionlimit e use o repositório vinculado import-recursion-demo e seus scripts de reprodução para verificar o comportamento. A tarefa estará concluída quando estiverem documentados o tamanho que as cadeias de importação precisam atingir para disparar RecursionError, o limite superior aproximado e a solução alternativa envolvendo a ordem de importação.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- documentation
- Tipo de issue
- Documentação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 58/100