Commit 270a01d
authored
Fix loop convergence with redefinitions (python#20865)
Currently, we reset the variable type each time we visit the initial
definition (textually first assignment). This can cause problems with
`--allow-redefinition-new`:
* Not all branches will be explored (see added test). This is a
correctness problem.
* Many loops will become runaway (will never converge to a fixed point)
while they actually can converge. Currently this is stopped by manual
cut-off. This is a performance problem.
The only non-trivial part here is handling of this pattern:
```python
for key in ("key_a", "key_b"):
some_typed_dict[key]
```
It is special-cased in regular mode, and this special-casing used to
work accidentally with redefinition allowed. Now I simply make the same
special-casing apply (since for loops can never be runaway on index).1 parent 4215dfd commit 270a01d
2 files changed
Lines changed: 48 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4401 | 4401 | | |
4402 | 4402 | | |
4403 | 4403 | | |
4404 | | - | |
4405 | | - | |
| 4404 | + | |
| 4405 | + | |
| 4406 | + | |
| 4407 | + | |
| 4408 | + | |
| 4409 | + | |
| 4410 | + | |
| 4411 | + | |
| 4412 | + | |
| 4413 | + | |
| 4414 | + | |
| 4415 | + | |
| 4416 | + | |
| 4417 | + | |
| 4418 | + | |
| 4419 | + | |
| 4420 | + | |
4406 | 4421 | | |
4407 | 4422 | | |
4408 | 4423 | | |
| |||
4784 | 4799 | | |
4785 | 4800 | | |
4786 | 4801 | | |
4787 | | - | |
| 4802 | + | |
4788 | 4803 | | |
4789 | 4804 | | |
4790 | 4805 | | |
| |||
4807 | 4822 | | |
4808 | 4823 | | |
4809 | 4824 | | |
4810 | | - | |
| 4825 | + | |
| 4826 | + | |
| 4827 | + | |
4811 | 4828 | | |
4812 | 4829 | | |
4813 | 4830 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1098 | 1098 | | |
1099 | 1099 | | |
1100 | 1100 | | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
1101 | 1128 | | |
1102 | 1129 | | |
1103 | 1130 | | |
| |||
0 commit comments