-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Classes that implement getitem are reported as incompatible with enumerate #9737
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
Comments
This is because we don't fully understand the "old-style" iteration protocol, where you make an iterable with just |
An easy fix is to add |
That doesn't work. It does make the mypy error go away but the code fails with For now the only work-around I found it to append a |
Maybe you can put the |
From what I could find, it seems the protocol is like this: So, the requirement for this to work is that the I tried updating the
|
That works, and I like it better than the comment since it is in the class and doesn't need to be put in every loop. |
Well, it seems that extending a class similar to my example is quite easy after all, simply add:
And everything works. |
You could do |
Bug Report
Mypy reports erroneously that a class that implements getitem is not suitable to be used with enumerate.
To Reproduce
Small example:
Expected Behavior
Running mypy on the above code should report no errors
Actual Behavior
Mypy reported:
Your Environment
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: