[issue22339] Incorrect behavior when subclassing enum.Enum

2014-09-16 Thread Ethan Furman
Ethan Furman added the comment: http://hg.python.org/cpython/rev/4135f3929b35 http://hg.python.org/cpython/rev/cdd412347827 -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker

[issue22339] Incorrect behavior when subclassing enum.Enum

2014-09-08 Thread Kiss György
Kiss György added the comment: Thanks for the tip! That looks much better. -- ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue22339] Incorrect behavior when subclassing enum.Enum

2014-09-06 Thread Ethan Furman
Ethan Furman added the comment: You could do the same kind of check in __new__, but consider this: class StrValues(MultiValueEnum): one = ('One' 'one', '1') two = ('two', 'Two', '2') In this scenario the 'Oneone' mistake would still not be autom

[issue22339] Incorrect behavior when subclassing enum.Enum

2014-09-06 Thread Kiss György
Kiss György added the comment: I found one thing which you can't do subclassing Enum what you can with metaclasses: enforcing type checking at class creation time. Values are passed to __new__ as positional arguments, so it's impossible to tell the difference between these two: class SingleVa

[issue22339] Incorrect behavior when subclassing enum.Enum

2014-09-05 Thread Kiss György
Kiss György added the comment: Oh, wow. I never really understood what _find_new_ did, now I do. > I'm not sure what you are trying to accomplish there. Exactly that, I'm just not as good. Oh well at least I found a bug! :) Thanks for the enlightenment! If the patch goes in, I also would like

[issue22339] Incorrect behavior when subclassing enum.Enum

2014-09-05 Thread Ethan Furman
Ethan Furman added the comment: Right. We can still use the alias machinery to accomplish this task for us, and avoid the metaclass hacking: -- python2 sample code # -*- coding: utf-8 -*- from enum import Enum class MultiValueEnum(Enum): def __new__(cl

[issue22339] Incorrect behavior when subclassing enum.Enum

2014-09-05 Thread Kiss György
Kiss György added the comment: > Is this a way to easily handle multiple aliases? You mean this MultiValueEnum implementation? (If not I don't understand the question, could you elaborate?) No, this is the opposite of aliases, because an alias is when the same value have multiple names, but t

[issue22339] Incorrect behavior when subclassing enum.Enum

2014-09-05 Thread Ethan Furman
Ethan Furman added the comment: My apologies for the confusion, and thanks for tracking it down. I'll get the patch in, but I'm curious how you actually use these Enums? Is this a way to easily handle multiple aliases? -- ___ Python tracker

[issue22339] Incorrect behavior when subclassing enum.Enum

2014-09-04 Thread Kiss György
Kiss György added the comment: Yes, sorry I forgot about that. Here is a minimal example: from enum import EnumMeta, Enum from types import DynamicClassAttribute class _MultiMeta(EnumMeta): def __init__(enum_class, cls, bases, classdict): # make sure we only have tuple values, not

[issue22339] Incorrect behavior when subclassing enum.Enum

2014-09-04 Thread Ethan Furman
Ethan Furman added the comment: Can you give an example of the code you were having problems with? -- assignee: -> ethan.furman nosy: +ethan.furman ___ Python tracker ___ __

[issue22339] Incorrect behavior when subclassing enum.Enum

2014-09-04 Thread Ethan Furman
Changes by Ethan Furman : -- nosy: +barry, eli.bendersky ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https:

[issue22339] Incorrect behavior when subclassing enum.Enum

2014-09-04 Thread Kiss György
New submission from Kiss György: There is a small inconvenience in the ``enum`` module. When I subclass ``enum.Enum`` and redefine the ``value`` dynamic attribute, the aliasing behavior doesn't work correctly, because ``member.value`` is used in some places instead of ``member._value_``. I atta