-
-
Notifications
You must be signed in to change notification settings - Fork 3k
itertools.product called on a Flag enum is inferred as object rather than class name #18684
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
Strangely, when I run this on a subset of the if __name__ == "__main__":
for flagitem1, flagitem2 in itertools.product(
Test_Flag_1.TF1a | Test_Flag_1.TF1b, Test_Flag_2.TF2a | Test_Flag_2.TF2b
):
test_func_1(flagitem1)
test_func_2(flagitem2) |
Similarly, expanding the function of if __name__ == "__main__":
for flagitem1 in Test_Flag_1:
for flagitem2 in Test_Flag_2:
test_func_1(flagitem1)
test_func_2(flagitem2) |
I can't reproduce this on the master branch, and we usually close things as soon as they are fixed on master. (You can also try it in the playground like this https://mypy-play.net/?mypy=master&python=3.12&gist=5dc24e94f25872e5c5d8ac032c4d8309) |
Thanks, can confirm that gist passes fine using master branch. Any idea when the fix will make it into a release, or advice on how one can use the master branch in a project in anticipation? Also, do you know which commit/PR resolved this - I would be interested in understanding better how mypy works. Don't worry if not though. |
To use dev build you can do something like this https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build (although this is not recommended for production code). Next release should be around mid-March.
I didn't bisect, but most likely it is my recent PR #18587 where I stopped using both class and instance for protocol inference against class object if an attribute is present on both class and the metclass (like |
Bug Report
When defining a class based on
Flag
from theenum
package I would expect items of the class to be of the type of the class when I iterate over them usingitertools
functions.However, instead mypy raises an error that they are instead of type
object
.To Reproduce
See playground link here: https://mypy-play.net/?mypy=latest&python=3.12&gist=5dc24e94f25872e5c5d8ac032c4d8309
Expand for code in playground to reproduce.
Expected Behavior
I would expect this to pass fine through mypy.
Actual Behavior
Instead items of the
Test_Flag_1
orTest_Flag_2
subclasses ofFlag
when iterated over usingitertools.product
are picked up by mypy as typeobject
instead of typeTest_Flag_1
orTest_Flag_2
.Your Environment
mypy.ini
(and other config files): NoneFull pip list:
The text was updated successfully, but these errors were encountered: