News for hackers. Stuff that matters.
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.