On Mon, Aug 30, 2021 at 12:57 AM Ronald Oussoren <ronaldousso...@mac.com> wrote: > On 28 Aug 2021, at 07:14, Christopher Barker <python...@gmail.com> wrote:
> >> Also +1 on a string flag, rather than an Enum. > > ou prefer strings for the options rather than an Enum? The enum clearly > documents what the valid options are for the option. > So does documentation (docstrings, useful error messages). I don't think the documentation built in to an Enum is any easier to access. In fact, looking now, I'm trying to see how an Enum provides any easy to access documentation -- other than looking at the creation code. As a rule, I don't think Enums provide documentation of the valid values, but rather, enforcement. e.g.: what are the valid values? what do they mean? To be honest, I haven't really used Enums much (in fact, only to mirror C enums in extension code), but part of that is because I have yet to see what the point is in Python, over simple string flags. I suppose they provide a real advantage for static typing, but other than that I just don't see it. But what they do is create a burden of extra code to read and write. Compare: from statistics import median result = median(the_data, nan_policy='omit') with: from statistics import median, NaNPolicy result = median(the_data, nan_policy=NaNPolicy.Omit) or maybe: import statistics as stats result = stats.median(the_data, nan_policy=stats.Omit) There are any number of ways to import, and names to create, but they all seem to me to be more awkward to use than a simple text flag. Ever since I started using Python, I've really appreciated the use of string flags :-) I do see how using an Enum makes things a bit easier for the author of a package (more DRY), but I don't think that should be the priority here. No one needs to convince me, but I would be interested in seeing the recommended way to import and use Enum flags - maybe it doesn't have to be as awkward as I think it is. -CHB -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/AW2HGEFFURMHXC6CPPSNOER7INZEINSS/ Code of Conduct: http://python.org/psf/codeofconduct/