Skip to content

Don't assume that for loop body index variable is always set - #18631

Merged
JukkaL merged 2 commits into
masterfrom
for-loop-binder
Feb 10, 2025
Merged

Don't assume that for loop body index variable is always set#18631
JukkaL merged 2 commits into
masterfrom
for-loop-binder

Conversation

@JukkaL

@JukkaL JukkaL commented Feb 7, 2025

Copy link
Copy Markdown
Collaborator

Fixes #18629. Fixes #16321. Fixes #8637.

@github-actions

github-actions Bot commented Feb 7, 2025

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/assertion/rewrite.py:731: error: Item "None" of "Optional[stmt]" has no attribute "lineno"  [union-attr]

kopf (https://github.com/nolar/kopf): 1.83x faster (40.2s -> 22.0s in a single noisy sample)

core (https://github.com/home-assistant/core)
+ homeassistant/components/blueprint/importer.py:223: error: Value of type "Any | None" is not indexable  [index]

pyodide (https://github.com/pyodide/pyodide)
+ src/py/pyodide/code.py:45: error: Unsupported operand types for + ("None" and "int")  [operator]
+ src/py/pyodide/code.py:45: note: Left operand is of type "int | None"

@JukkaL

JukkaL commented Feb 7, 2025

Copy link
Copy Markdown
Collaborator Author

All the new mypy_primer errors look right.

@JukkaL
JukkaL requested a review from ilevkivskyi February 7, 2025 15:37
@ilevkivskyi

Copy link
Copy Markdown
Member

@JukkaL I think this may also fix #8637 (an old high priority bug), could you please double-check?

@JukkaL

JukkaL commented Feb 10, 2025

Copy link
Copy Markdown
Collaborator Author

I think this may also fix #8637 (an old high priority bug)

Yes, it is fixed!

@JukkaL
JukkaL merged commit f946af4 into master Feb 10, 2025
@JukkaL
JukkaL deleted the for-loop-binder branch February 10, 2025 10:00
x612skm pushed a commit to x612skm/mypy-dev that referenced this pull request Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants