[Python-Dev] PEP 435 - ref impl disc 2 (original) (raw)
Ethan Furman ethan at stoneleaf.us
Sun May 5 16:49:44 CEST 2013
- Previous message: [Python-Dev] PEP 435 - ref impl disc 2
- Next message: [Python-Dev] PEP 435 - ref impl disc 2
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 05/05/2013 01:08 AM, Nick Coghlan wrote:
On Sun, May 5, 2013 at 5:21 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
There's also the code in enumtype.call that ensures Enum.repr and Enum.str are used in preference to those from the value type. (Specifically, the code at https://bitbucket.org/stoneleaf/ref435/src/758d43b9f7327cd61dc2e45050539b6b5db1c4e3/ref435.py?at=default#cl-152 that ignores repr and str from non-Enum types) I think this needs to be documented more clearly - if you want to keep a custom repr or str when mixing Enum (or an Enum subclass) with another type, then you need to explicitly set them in your subclass. (e.g. in Glenn's case, setting "repr = NamedValue.repr")
Certainly the docs need to be clear about this. I don't think the PEP needs to be. (Apologies if you were not referring to the PEP.)
The more reasonable logic to me seems to be to figure out the "first enum base" and the "first non-enum base" based on:
enumbases = [base for base in enumclass.mro() if issubclass(base, Enum)] nonenumbases = [base for base in enumclass.mro() if not issubclass(base, Enum)] Then, if the current new, str or repr implementation is the same as that for the first non-enum base, we replace it with the impl from the first enum base.
Fair point -- working on it.
--
Ethan
- Previous message: [Python-Dev] PEP 435 - ref impl disc 2
- Next message: [Python-Dev] PEP 435 - ref impl disc 2
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]