
On Tue, Aug 31, 2021 at 2:19 AM Christopher Barker <pythonchb@gmail.com> wrote:
On Mon, Aug 30, 2021 at 12:57 AM Ronald Oussoren <ronaldoussoren@mac.com> wrote:
On 28 Aug 2021, at 07:14, Christopher Barker <pythonchb@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.
They provide a *huge* advantage when they can be combined. It's easy to accept a flags argument that is the bitwise Or of a collection of flags, and then ascertain whether or not a specific flag was included. The repr of such a combination is useful and readable, too. ChrisA