4 ms·
In some typed/compiled languages, a substantial benefit of using enums is that it provides some way to automatically determine if you've handled every eventuali
by icegreentea2 6y ago
In some typed/compiled languages, a substantial benefit of using enums is that it provides some way to automatically determine if you've handled every eventuality. That's super not a part of normal Python as you've mentioned.
The second part of crimsonalucard1's post was referring to somehow hacking in that type of functionality into Python.
I think you could somehow do that with nested context managers - something like:
with EnumChecker(e) as checker:
with checker(enum_type.A):
# do thing
with checker(enum_type.B):
# do thing
...
Where `e` is an instance of `enum_type`, and the inner context managers acting as if/case statements, then you could on any single execution of the code block (so you only need a single test case) ensure that you covered all states.