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

mypy error when trying to iterate over aenum.Enum subclass #29

Open
Jylpah opened this issue May 26, 2023 · 1 comment
Open

mypy error when trying to iterate over aenum.Enum subclass #29

Jylpah opened this issue May 26, 2023 · 1 comment

Comments

@Jylpah
Copy link

Jylpah commented May 26, 2023

aenum: aenum-3.1.12
Mypy: mypy-1.3.0
Python: Python 3.11.3

mypy complains Type[IterFailingEnum]" has no attribute "__iter__" (not iterable) [attr-defined] when trying to iterate over anum.Enum subclass. mypy does not complain when iterating over an standard library Enum subclass. The code works still.

Is this an error in mypy or consequence of missing proper type hinting support in aenum?

Reproduceable error case

import aenum # type: ignore

class IterFailingEnum(aenum.Enum):
	_init_ = 'value fullname'
	_settings_ = aenum.MultiValue
	one = 1, 'One'
	two = 2, 'Two'
	three = 3, 'Three'

for e in IterFailingEnum:  # "Type[IterFailingEnum]" has no attribute "__iter__" (not iterable)  [attr-defined]
	print(e.fullname)
@aquirdTurtle
Copy link

aquirdTurtle commented Dec 14, 2023

Similarly,

from aenum import Enum

class test(Enum):
    HELLO = "WORLD"
    FOO = "BAR"

    @classmethod
    def _missing_(cls, value: str):
        """Allow for case insensitive matching"""
        for member in cls:
            print(member)

And pyright gives error: "type[test]" is not iterable, while this works with the stdlib enum.

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

No branches or pull requests

2 participants