[issue29752] Enum._missing_ not called for __getitem__ failures

2018-01-21 Thread Ethan Furman

Ethan Furman  added the comment:

I'm not convinced this piece needs to be in the stdlib.  Unlike other bits that 
need extensive metaclass support this is trivial to add:

  class DerivedEnumMeta(EnumMeta):
def __getitem__(cls, name):
try:
return cls._member_map_[name]
except KeyError:
result = cls._missing_name_(name)
if isinstance(result, cls):
return result
raise

--
resolution:  -> rejected
stage: test needed -> resolved
status: open -> closed
versions:  -Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29752] Enum._missing_ not called for __getitem__ failures

2018-01-18 Thread Ethan Furman

Ethan Furman  added the comment:

To move this forward:

The proposal is to add support for a new method, _missing_name_, which is 
called by __getitem__.

If such a method does not exist, the normal AttributeError exception is raised;

otherwise, the _missing_name_ method is called with the invalid name and should 
return a matching member or None;
- if None, the normal AttributeError exception is raised
- if a member, it is returned
- otherwise, a Type(?)Error is raised

--
title: Enum._missing_ not called for __getattr__ failures -> Enum._missing_ not 
called for __getitem__ failures

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com