Search code examples
pythonpython-3.xlistenumeration

Python 3 Enumeration List Value doesn't support membership test


from enum import IntEnum
from typing import List
class EnumClass(IntEnum):
   A = 1
   B = 2

   @staticmethod
   def listofconditions() -> 'List[EnumClass]':
      return [EnumClass.A.numerator, \
              EnumClass.B.numerator]


if 1 in EnumClass.listofconditions:
    pass

yields:

[pylint]:E1135 Value 'EnumClass.listofconditions' doesn't support membership test

(I posted this for others Googling a solution to this cryptic message in order to makes sense of it. Solution to follow)


Solution

  • Change code to:

    if 1 in EnumClass.listofconditions():