Uh oh!
There was an error while loading. Please reload this page.
Remove redundant inheritances from Iterator in itertools - #12816
Conversation
Diff from mypy_primer, showing the effect of this PR on open source code: python-chess (https://github.com/niklasf/python-chess)
+ chess/pgn.py:194: error: No overload variant of "iter" matches argument type "object" [call-overload]+ chess/pgn.py:194: note: Possible overload variants:+ chess/pgn.py:194: note: def [_SupportsNextT: SupportsNext[Any]] iter(SupportsIter[_SupportsNextT], /) -> _SupportsNextT+ chess/pgn.py:194: note: def [_T] iter(_GetItemIterable[_T], /) -> Iterator[_T]+ chess/pgn.py:194: note: def [_T] iter(Callable[[], _T | None], None, /) -> Iterator[_T]+ chess/pgn.py:194: note: def [_T] iter(Callable[[], _T], object, /) -> Iterator[_T]
xarray (https://github.com/pydata/xarray)
+ xarray/core/dataset.py: note: In function "_get_chunk":+ xarray/core/dataset.py:280: error: Argument 1 to "difference" of "set" has incompatible type "object"; expected "Iterable[Any]" [arg-type]+ xarray/core/dataset.py: note: At top level:
jax (https://github.com/google/jax)
+ jax/_src/numpy/linalg.py:2087: error: Unused "type: ignore" comment [unused-ignore] |
Both mypy primer hits look like instances of python/mypy#4373 to me. python-chess simplifies to: importitertoolsfoo: list[int] = []
condition=Trueiter(itertools.pairwise(foo) ifconditionelse [])xarray simplifies to importitertoolscond=Truefoo: list[int] = []
set().difference(range(1) ifcondelseitertools.accumulate(foo))The unused ignore from jax is something involving an overloaded function that I don't fully understand yet. I played around with it a bunch, and ended up with this simplified form: importitertoolsfromtypingimportoverload@overloaddeffoo(arg1: str) ->str: ...
@overloaddeffoo(arg1: str, arg2: int) ->int: ...
deffoo(arg1: str, arg2: int|None=None) ->int|str:
return1defbar() ->int|str:
arrs: list[int] = []
result=foo(*itertools.chain(arrs))
reveal_type(result)
returnresultWithout this change, this produces: With this MR in place, mypy gives: This might also be a mypy bug? It seems like when itertools.chain is explicitly I realize that this form of it could never really work; the original argument types are very different and include a |
AlexWaygood
commented
Oct 18, 2024
I'm a bit concerned by the primer output here. Even if the root cause of these false positives is a mypy bug, we should try not to make changes to the stubs if they end up hurting users of type checkers more than they end up helping users of type checkers. All else being equal, I agree it's best to have a class's MRO in the stubs be as accurate as it can possibly be, but that shouldn't come at any cost. |
tungol
commented
Oct 18, 2024
Would you like me to put up an MR reversing the change? |
AlexWaygood
commented
Oct 18, 2024
I would prefer that, yes :-) |
…hon#12816)" This reverts commit 281dd35.
No description provided.