[Python-ideas] Change magic strings to enums
Jacco van Dorp
j.van.dorp at deonet.nl
Thu Apr 26 05:37:39 EDT 2018
I'm kind of curious why everyone here seems to want to use IntFlags
and other mixins. The docs themselves say that their use should be
minimized, and tbh I agree with them. Backwards compatiblity can be
maintained by allowing the old value and internally converting it to
the enum. Combinability is inherent to enum.Flags. There'd be no real
reason to use mixins as far as I can see ?
2018-04-26 10:52 GMT+02:00 INADA Naoki <songofacandy at gmail.com>:
>>> It could be great. But I afraid this may add too much complexity in C
> code. Maybe try to implement a simple and fast Enum for using it in the
> stdlib and extend it with a richer interface in the enum module?
>
>
>> I think we can do something similar to ABCMeta, i.e. the metaclass itself
> will stay defined in Python, but the "hottest" parts of its methods will be
> replaced with helper functions written in C.
>> This way we can limit complexity of the C code while still getting almost
> all the performance benefits.
>
>> --
>> Ivan
>
>
> Adding C speedup module has high bar, especially performance gain is only
> on startup time.
>
> Personally speaking, I want speedup module for `re.compile` than enum.
> In case of enum, I feel CONSTANT = "magic" is enough for most cases.
> re doesn't have such workaround, and using third party regular expression
> library has
> very high bar, especially when using it in stdlib.
>
> But there were some -1 on adding speedup module for re.
> I think it's same to enum.
>
> So I think we should:
>
> * Don't use enum blindly; use it only when it's very far better than CONST
> = "magic".
> * Add faster API which bypass some slow part, especially for
> IntEnum.convert() or IntFlag.convert() in socket module.
>
> Regards,
>
> --
> INADA Naoki <songofacandy at gmail.com>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
More information about the Python-ideas
mailing list