aenum icon indicating copy to clipboard operation
aenum copied to clipboard

mypy error when trying to iterate over aenum.Enum subclass

Open Jylpah opened this issue 1 year ago • 1 comments

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)

Jylpah avatar May 26 '23 10:05 Jylpah

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.

aquirdTurtle avatar Dec 14 '23 17:12 aquirdTurtle