News for hackers. Stuff that matters.
Re:Using Enumerated Types in Python by ramraj07 on Saturday June 06, 2020 @05:07PM (#23442230)
Have constantly struggled over how to deal with this problem. The biggest need for enums has been function arguments which can be one of a few values.

In the end, the Literal class from the typing library seems like the simplest, least wordy solution. Pycharm and mypy capture any mistakes you make which seem more than sufficient for my use cases.

Re:Using Enumerated Types in Python by nerdponx on Saturday June 06, 2020 @05:42PM (#23442471)
Why not use Enum anyway, which works fine with MyPy? I don't mind the verbosity, it's a one-time commitment to what, 10 extra lines of code?
Re:Using Enumerated Types in Python by ramraj07 on Saturday June 06, 2020 @06:15PM (#23442735)
Issue is I'll now need two imports everytime I call this method, which becomes mildly annoying. I was doing this, but a lot of times the Literal type seems more than sufficient. It also seems to play real nice with pydantic so it's an added win!
Re:Using Enumerated Types in Python by nerdponx on Saturday June 06, 2020 @10:16PM (#23444214)
I'm not sure what you mean by "two imports".

If you define your Enum subclass in the same file, you use one import for enum.Enu. If you eschew enums and use Literal, you use one import for typing.Literal.