On Tue, 24 Apr 2018 23:58:19 +1000 Nick Coghlan <ncogh...@gmail.com> wrote:
> On 24 April 2018 at 22:52, Jacco van Dorp <j.van.d...@deonet.nl> wrote: > > A bit ago I was reading some of the python docs ( > > https://docs.python.org/3.6/library/warnings.html ), the warning > > module, and I noticed a table of magic strings. > > > > I can think of a few other places where magic strings are used - for > > example, string encoding/decoding locales and strictness, and probably > > a number of other places. > > > > Since Python 3.4, We've been having Enums. > > > > Wouldn't it be cleaner to use enums by default instead of those magic > > strings ? for example, for warnings filter actions, (section 29.5.2), > > quite near the top of the page. > > "It's cleaner" isn't a user problem though. The main justification for > using enums is that they're easier to interpret in log messages and > expection tracebacks than opaque constants, and that argument is much > weaker for well-chosen string constants than it is for other constants > (like the numeric constants in the socket and errno modules). Also beware the import time cost of having a widely-used module like "warnings" depend on the "enum" module and its own dependencies. Regards Antoine. _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/