I've honestly never really used an Enum, so I'm not an expert here.
An idea might be using string flags, but setting module level constants
equal to the string flag, so that you can use either. For example (using
the ipython shell because it's easier in email with quoting and all):

In [1]: import statistics as stats
In [2]: stats.NAN_IGNORE
Out [2]: 'ignore'
In [3]: stats.median([3, float('nan'), 5], nan_policy=stats.NAN_IGNORE) ==
stats.median([3, float('nan'), 5], nan_policy='ignore')
Out [3]: True

I do think that it doesn't matter too much and an issue should be submitted
soon.

On Tue, Aug 31, 2021, 4:59 PM Christopher Barker <python...@gmail.com>
wrote:

> First:
>
> I started this specifically in the context of the stats package and the
> NaN handling flag, but it did turn into a ore general discussion of Enums,
> so a final thought:
>
> On Tue, Aug 31, 2021 at 4:17 AM Ronald Oussoren <ronaldousso...@mac.com>
> wrote:
>
>>
>> Not just static typing, but static analysis in general. Tools like flake8
>> will complain about typos, completion tools can help typing, ….
>>
> ...
>
>
>> I tend to use constants instead of string literals because of better
>> static analysis, and try to convert uses to enums over time.  String flags
>> work as well, but I’ve had too much problems due to typo’s in string
>> literals that weren’t caught by incomplete tests.  Being able to at least
>> run a listing tool to find basic issues like typo’s is very convenient.
>> But YMMV.
>>
>
> I think this is the crux or it -- Enums are far more suited to static
> analysis.
>
> And that reflects a shift in Python over the years. Most of the changes in
> Python have made it a better "systems" language, and some have made it a
> somewhat more awkward "scripting" language.
>
> Features to support static analysis are a good example -- far less
> important for "scripting' that "systems programming".
>
> Personally, I find it odd -- I've spent literally a couple decades telling
> people that Python's dynamic nature is a net plus, and the bugs that static
> typing (and static analysis I suppose) catch for you are generally shallow
> bugs. (for example: misspelling a string flag is a shallow bug).
>
> But here we are.
>
> Anyway, if you are writing a quick script to calculate a few statistics, I
> think a string flag is easier. If you are writing a big system with some
> statistical calculations built in, you will appreciate the additional
> safety of an Enum. It's hard to optimize for different use cases.
>
> - 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/LJ334TFG67PR3G2E6WNZC7YEG3K2XMEN/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
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/LRJFFW25UJIH6HNQ6LOTZ5T6M27Y23KC/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to