Skip to content

Conversation

@p-sawicki
Copy link
Collaborator

Fixes #20697

Changed the base type of itertools.batched from Iterator[tuple[_T_co, ...]] to Iterator[_T_co] in the stub and patch files so that mypy no longer reports an error due to a mismatched return type of __next__.

@github-actions
Copy link
Contributor

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

openlibrary (https://github.com/internetarchive/openlibrary)
- openlibrary/solr/data_provider.py: note: In member "preload_metadata" of class "DataProvider":
- openlibrary/solr/data_provider.py:214: error: Argument 1 to "_get_lite_metadata" of "DataProvider" has incompatible type "tuple[tuple[str, ...], ...]"; expected "Sequence[str]"  [arg-type]
- openlibrary/solr/data_provider.py:224: error: Argument 1 to "_get_lite_metadata_direct" of "DataProvider" has incompatible type "tuple[str, ...]"; expected "str"  [arg-type]

@JelleZijlstra
Copy link
Member

Why does this need to be fixed here and not in typeshed?

@ilevkivskyi
Copy link
Member

@JelleZijlstra IIRC typeshed doesn't want to have explicit protocol bases. This is why we used to have the original patch in the first place. TBH I don't remember why we can't fix this in mypy (but at least this will add some perf penalty, since protocols are a bit slower than nominal subclasses).

@ilevkivskyi
Copy link
Member

Oh, wait, now there is an actual inconsistency in the type of __next__(), yeah, this looks fishy and should be reported to typeshed.

@ilevkivskyi
Copy link
Member

Oh, sorry, but the inconsistency is caused by our patch, all looks good then, ignore my previous comment.

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Yeah, I checked discussion on typeshed, they are aware this will be a breaking change, but the decision was that this is fine, since this is a relatively new feature (Python 3.12), and this will allow more precise item types.

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.

Running mypy on itertools.pyi fails

3 participants