Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix __iter__ return type to Iterator #129

Merged
merged 3 commits into from Dec 13, 2023

Conversation

altescy
Copy link
Contributor

@altescy altescy commented Dec 12, 2023

This pull request modifies the type hint for __iter__ to return Iterator instead of Iterable 1.
Mypy raises the error if __iter__ returns Iterable like below:

from typing import Iterable

class Foo:
    def __iter__(self) -> Iterable[str]:
        return iter("abc")

for value in Foo(): # E: "Iterable[str]" has no attribute "__next__"  [attr-defined]
    ...

Footnotes

  1. iterator.__iter__

Copy link

cla-checker-service bot commented Dec 12, 2023

💚 CLA has been signed

Copy link
Member

@pquentin pquentin left a comment

Choose a reason for hiding this comment

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

Thanks! Great catch. LGTM.

@pquentin pquentin merged commit 6baac50 into elastic:main Dec 13, 2023
10 checks passed
github-actions bot pushed a commit that referenced this pull request Dec 13, 2023
Co-authored-by: Quentin Pradet <quentin.pradet@elastic.co>
(cherry picked from commit 6baac50)
pquentin added a commit that referenced this pull request Dec 13, 2023
* Fix __iter__ return type to Iterator (#129)

Co-authored-by: Yasuhiro Yamaguchi <altescy@fastmail.com>
Co-authored-by: Quentin Pradet <quentin.pradet@elastic.co>
@altescy altescy deleted the fix-iter-type-hints branch December 13, 2023 08:16
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.

None yet

2 participants