Skip to content

[mypyc] Fix evaluation of iterable in list comprehension twice #10599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2021

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jun 8, 2021

This could result in a crash if the second evaluation results
in a shorter list, such as in this example (besides being incorrect
overall):

a = [s for s in f.readlines()]

f.readlines() was called twice, resulting in an empty list on
the second call. This caused the list object constructed in the
comprehension to have a NULL item, which is invalid.

This fixes mypy --install-types in compiled mode.

Fixes #10596.

This could result in a crash if the second evaluation results
in a shorter list, such as in this example (besides being incorrect
overall):

```
a = [s for s in f.readlines()]
```

`f.readlines()` was called twice, resulting in an empty list on
the second call. This caused the list object to have a NULL item,
which is invalid.

This should fix `mypy --install-types` in compiled mode.
@JukkaL JukkaL merged commit e37dfb1 into master Jun 8, 2021
@JukkaL JukkaL deleted the mypyc-list-comprehension branch June 8, 2021 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mypy --install-types segfaults
1 participant