Skip to content

fix Iterating over enumerated tuple loses typing information #1323#4090

Open
asukaminato0721 wants to merge 1 commit into
facebook:mainfrom
asukaminato0721:1323
Open

fix Iterating over enumerated tuple loses typing information #1323#4090
asukaminato0721 wants to merge 1 commit into
facebook:mainfrom
asukaminato0721:1323

Conversation

@asukaminato0721

Copy link
Copy Markdown
Contributor

Summary

Fixes #1323

Added builtins.enumerate to stdlib type access.

Added a precise builtin enumerate call fast path, using existing iteration logic so tuple literal element types are preserved.

Test Plan

update test

@meta-cla meta-cla Bot added the cla signed label Jul 9, 2026
@github-actions github-actions Bot added the size/s label Jul 9, 2026
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

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

rotki (https://github.com/rotki/rotki)
- ERROR rotkehlchen/externalapis/cryptocompare.py:495:41-48: Argument `Price | Unknown` is not assignable to parameter `iterable` with type `Iterable[@_]` in function `enumerate.__new__` [bad-argument-type]
+ ERROR rotkehlchen/externalapis/cryptocompare.py:495:41-48: Type `Price` is not iterable [not-iterable]

bokeh (https://github.com/bokeh/bokeh)
- ERROR src/bokeh/layouts.py:307:34-37: Argument `UIElement | list[UIElement | None] | None` is not assignable to parameter `iterable` with type `Iterable[@_]` in function `enumerate.__new__` [bad-argument-type]
+ ERROR src/bokeh/layouts.py:307:34-37: Type `UIElement` is not iterable [not-iterable]
+ ERROR src/bokeh/layouts.py:307:34-37: Type `None` is not iterable [not-iterable]

spark (https://github.com/apache/spark)
- ERROR python/pyspark/pandas/frame.py:7176:45-57: Argument `list[Unknown] | tuple[Unknown | None] | Unknown | None` is not assignable to parameter `iterable` with type `Iterable[Unknown | None]` in function `enumerate.__new__` [bad-argument-type]
+ ERROR python/pyspark/pandas/frame.py:7176:45-57: Type `None` is not iterable [not-iterable]

cwltool (https://github.com/common-workflow-language/cwltool)
- ERROR cwltool/command_line_tool.py:1251:46-56: Argument `MutableMapping[str, CWLOutputType | None] | MutableSequence[CWLOutputType | None] | bool | float | int | str | CWLDirectoryType | CWLFileType | None` is not assignable to parameter `inputid` with type `str` in function `cwltool.process.shortname` [bad-argument-type]
+ ERROR cwltool/command_line_tool.py:1251:46-56: Argument `MutableMapping[str, CWLOutputType | None] | MutableSequence[CWLOutputType | None] | bool | float | int | str | CWLDirectoryType | CWLFileType | Unknown | None` is not assignable to parameter `inputid` with type `str` in function `cwltool.process.shortname` [bad-argument-type]

pwndbg (https://github.com/pwndbg/pwndbg)
- ERROR pwndbg/commands/plist.py:418:33-42: Argument `list[int] | None` is not assignable to parameter `iterable` with type `Iterable[int]` in function `enumerate.__new__` [bad-argument-type]
+ ERROR pwndbg/commands/plist.py:418:33-42: Type `None` is not iterable [not-iterable]

apprise (https://github.com/caronc/apprise)
- ERROR apprise/plugins/sns.py:805:44-49: Argument `str | Any` is not assignable to parameter `object` with type `LiteralString` in function `list.append` [bad-argument-type]
+ ERROR apprise/plugins/sns.py:805:44-49: Argument `str | Unknown` is not assignable to parameter `object` with type `LiteralString` in function `list.append` [bad-argument-type]

mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
- ERROR pymongo/asynchronous/cursor.py:915:56-57: Argument `Iterable[Unknown] | SupportsItems[Unknown, Unknown]` is not assignable to parameter `iterable` with type `Iterable[Unknown]` in function `enumerate.__new__` [bad-argument-type]
+ ERROR pymongo/asynchronous/cursor.py:915:56-57: Type `SupportsItems[Unknown, Unknown]` is not iterable [not-iterable]
- ERROR pymongo/synchronous/cursor.py:913:56-57: Argument `Iterable[Unknown] | SupportsItems[Unknown, Unknown]` is not assignable to parameter `iterable` with type `Iterable[Unknown]` in function `enumerate.__new__` [bad-argument-type]
+ ERROR pymongo/synchronous/cursor.py:913:56-57: Type `SupportsItems[Unknown, Unknown]` is not iterable [not-iterable]

ibis (https://github.com/ibis-project/ibis)
- ERROR ibis/expr/schema.py:83:44-54: Argument `Attribute` is not assignable to parameter `iterable` with type `Iterable[@_]` in function `enumerate.__new__` [bad-argument-type]
+ ERROR ibis/expr/schema.py:83:44-54: Type `Attribute` is not iterable [not-iterable]

strawberry (https://github.com/strawberry-graphql/strawberry)
- ERROR strawberry/experimental/pydantic/conversion.py:47:38-42: Argument `Unknown | None` is not assignable to parameter `iterable` with type `Iterable[Unknown]` in function `enumerate.__new__` [bad-argument-type]
+ ERROR strawberry/experimental/pydantic/conversion.py:47:38-42: Type `None` is not iterable [not-iterable]

sockeye (https://github.com/awslabs/sockeye)
- ERROR sockeye/checkpoint_decoder.py:166:83-89: Argument `tuple[Any, ...]` is not assignable to parameter `strings` with type `list[str]` in function `sockeye.inference.make_input_from_multiple_strings` [bad-argument-type]
+ ERROR sockeye/checkpoint_decoder.py:166:83-89: Argument `tuple[Any, ...] | Unknown` is not assignable to parameter `strings` with type `list[str]` in function `sockeye.inference.make_input_from_multiple_strings` [bad-argument-type]

pandas (https://github.com/pandas-dev/pandas)
- ERROR pandas/core/arrays/interval.py:1578:50-58: Argument `NaTType | Period | Timedelta | Timestamp | Any` is not assignable to parameter `right` with type `int` in function `pandas._libs.interval.Interval.__init__` [bad-argument-type]

core (https://github.com/home-assistant/core)
- ERROR homeassistant/components/forked_daapd/media_player.py:782:42-62: Argument `int | list[Unknown]` is not assignable to parameter `iterable` with type `Iterable[@_]` in function `enumerate.__new__` [bad-argument-type]
+ ERROR homeassistant/components/forked_daapd/media_player.py:782:42-62: Type `int` is not iterable [not-iterable]

sphinx (https://github.com/sphinx-doc/sphinx)
- ERROR sphinx/domains/cpp/_ast.py:4443:31-45: Argument `list[ASTTemplateIntroduction | ASTTemplateParams] | None` is not assignable to parameter `iterable` with type `Iterable[ASTTemplateIntroduction | ASTTemplateParams]` in function `enumerate.__new__` [bad-argument-type]
+ ERROR sphinx/domains/cpp/_ast.py:4443:31-45: Type `None` is not iterable [not-iterable]

discord.py (https://github.com/Rapptz/discord.py)
- ERROR discord/abc.py:578:44-81: Argument `list[PermissionOverwrite] | list[@_] | object` is not assignable to parameter `iterable` with type `Iterable[@_]` in function `enumerate.__new__` [bad-argument-type]
+ ERROR discord/abc.py:578:44-81: Type `object` is not iterable [not-iterable]

optuna (https://github.com/optuna/optuna)
- ERROR optuna/visualization/_rank.py:273:68-80: Argument `list[float] | None` is not assignable to parameter `iterable` with type `Iterable[float]` in function `enumerate.__new__` [bad-argument-type]
+ ERROR optuna/visualization/_rank.py:273:68-80: Type `None` is not iterable [not-iterable]

schema_salad (https://github.com/common-workflow-language/schema_salad)
+ ERROR src/schema_salad/sourceline.py:224:35-40: Argument `list[int] | list[Never]` is not assignable to parameter `lc` with type `list[int] | None` in function `cmap` [bad-argument-type]

@meta-codesync

meta-codesync Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

@grievejia has imported this pull request. If you are a Meta employee, you can view this in D111271389.

@yangdanny97 yangdanny97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iterating over enumerated tuple loses typing information

2 participants