News for hackers. Stuff that matters.
Re:Using Enumerated Types in Python by icegreentea2 on Saturday June 06, 2020 @03:01PM (#23441489)
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.

There are no comments on this comment yet.