Based on the answer of Blue Ice - thank you for the push to the enum direction.
As I stumbled over the same issue, this is my working example, also raising a type error.
#!/usr/bin/python3
from enum import Enum
class InvalidParameters(Enum):
''' This is used to demonstrate the type error. '''
ILLEGAL = 0
class ValidParameters(Enum):
''' This is used to pass a valid parameter. '''
LEGAL = 0
def someFunc(param : ValidParameters) -> None:
''' Do some necessary stuff. '''
if not type(param) is ValidParameters:
raise TypeError('Parameter has to be of type ValidParameters')
print(f'{ValidParameters(param)}')
if __name__ == '__main__':
''' Some test cases, dis-/enable them one by one. '''
someFunc('Wrong')
#someFunc(InvalidParameters.ILLEGAL)
#someFunc(ValidParameters.LEGAL)
SystemExit(0)