While I agree that Enum’s are a bit clunky (and IMO removing in is a poor choice), is this going to really take be that hard to work with or that difficult to validate?
Enums are types that raise ValueError, like any other, so it’s not that confusing and fits in with Django’s existing validation code. Once we have coerced the input into an enum member then validation against choices is simple no? On 11 January 2019 at 13:30:40, James Bennett (ubernost...@gmail.com) wrote: Shai, your rebuttal still misses an important use case, which is containment. To continue with your example of a 'SchoolYear(str, Enum)', the following will both be False: 'FR' in SchoolYear 'FR' in SchoolYear.__members__ The first of those is also becoming illegal soon -- attempting an 'in' comparison on an Enum, using an operand that isn't an instance of Enum, will become a TypeError in Python 3.8. Instead you have to do something like: 'FR' in [choice.value for choice in SchoolYear] to get a containment check. And you need a containment check to perform validation. There are other ways to do it, but they're all clunky, and this is going to be code that people have to write (in some form) over and over again, unless we build our own choice abstraction that hides this by wrapping an Enum and implementing a __contains__ that does what people want. And you'd basically have to do it in a wrapper, because Enum does metaclass stuff that interferes with a typical "just subclass and override" approach. So I still don't think this is going to work for the model-choice use case without a lot of fiddling (and I'm still not a fan of the enum module in general, largely because it seems to have gone out of its way to make this use case difficult to implement). -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAL13Cg_KEtgmNzRo%3DC8cnCiNsukr5YOCTv3MF8AybV%3D%3DiUXP0g%40mail.gmail.com <https://groups.google.com/d/msgid/django-developers/CAL13Cg_KEtgmNzRo%3DC8cnCiNsukr5YOCTv3MF8AybV%3D%3DiUXP0g%40mail.gmail.com?utm_medium=email&utm_source=footer> . For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAFNZOJOSdesTHqak%3Dstj%2Be65YBYOPg2PiZD7iMpoAH2kSpa%2Bgw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.