I use enumerations in Python 2.7 with enum34, which backports the enumerations of Python 3.4 to 2.7.
In my script I have functions which get some entry of an enumeration. Since this may become a multi-author project, I want to declare methods explicitly type safe:
def someFunction(some_enum_item):
"""
:param some_enum_item: one entry out of my Enum SAMPLE_ENUM
:type some_enum_item: SAMPLE_ENUM
"""
if isinstance(some_enum_item, SAMPLE_ENUM):
...
else:
...
So, I want to test against the parameter if it is really an instance of SAMPLE_ENUM
and additionally I want to have an IDE recognizing that the function only takes entries of a specific Enum.
Is isinstance
the right way to test if the parameter has the correct type?
How am I modelling the :type some_enum_item:
correctly? At the moment :type some_enum_item: SAMPLE_ENUM
just checks if the parameter is the class SAMPLE_ENUM
rather than an item of this enumeration (hence, the IDE complains when I'm passing an entry of the enumeration to the function).