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?
[ Parent
| on HN ]
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!
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.