[New-bugs-announce] [issue34282] Enum._convert shadows members named _convert
orlnub123
report at bugs.python.org
Mon Jul 30 13:36:39 EDT 2018
New submission from orlnub123 <orlnub123 at gmail.com>:
If an enum has a member named _convert it gets shadowed by the _convert method as shown below.
>>> import enum
>>>
>>> class Test(enum.Enum):
... _convert = enum.auto()
...
>>> Test._convert
<bound method Enum._convert of <enum 'Test'>>
I've came up with a couple of solutions:
1. Add _convert to the invalid names list, next to mro
2. Rename _convert to _convert_ as sunder names are reserved
3. Move _convert to the metaclass
I think the first solution would be the worst as it would break existing enums that have _convert as a member (although unusable).
The problem with the second solution would be breaking external code that uses it although I think that's a moot point as it's meant for internal use. Another shortcoming would be having to update all the stdlib code that uses it.
The third solution might be a bit confusing on its own if an existing enum with a _convert member suddenly removed it leaving you with a bound method instead of raising an AttributeError.
----------
components: Library (Lib)
messages: 322681
nosy: ethan.furman, orlnub123
priority: normal
severity: normal
status: open
title: Enum._convert shadows members named _convert
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34282>
_______________________________________
More information about the New-bugs-announce
mailing list