Attempting to assign an infinte generator to an extended slice hangs indefinitely instead of raising ValueError
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Bug report
Bug description:
For builtin types which support assignment to extended slices (i.e. slices with a step other than 1), the length of the iterable being assigned from must be equal to the length of the slice being assigned to. However, Python appears to determine the length of the iterable by repeatedly calling next() until StopIteration is raised.
In the event that an object never raises StopIteration, this creates an infinite evaluation loop, even though it should be apparent that the two sizes are not equal once the size of the slice has been exceeded. See the example below:
class MyGen:
def __iter__(self):
while True:
yield "foo"
l = [0,1,2,3]
l[::2] = range(10) # raises ValueError: attempt to assign sequence of size 10 to extended slice of size 2
l[::2] = MyGen() # hangs indefinitely despite returning more than 2 values
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Linked PRs
- gh-146272
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
Reproduza o travamento com os exemplos de atribuição a extended slices na issue e, em seguida, rastreie o caminho de atribuição builtin a extended slices que consome o iterable. Adicione um teste de regressão que cubra um gerador infinito e verifique se a atribuição gera ValueError assim que o comprimento do slice é excedido.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- backend
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 25/100