New submission from Ethan Furman <et...@stoneleaf.us>:

The following code should work (from 
https://stackoverflow.com/a/46780742/208880):


    class BaudRate(Enum):

        cls = vars()
        regexp = r"(?:^|,)B(?P<rate>\d+)"
        rates = sorted(map(int, re.findall(regexp, ",".join(dir(termios)))))
        for value in rates:
            cls['B%d' % value] = value

        @classmethod
        def valid_rate(cls, value):
            return (any(value == item.value for item in cls))


This doesn't work because EnumMeta does not allow names to be reassigned nor 
deleted.  aenum gets around this by allowing an _ignore_ attribute which 
contains the names that should not be tracked (and, in fact, those names are 
removed from the final class).

Unless a better idea is put forward, I will add _ignore_ support to Enum.

----------
assignee: ethan.furman
messages: 304487
nosy: barry, eli.bendersky, ethan.furman
priority: normal
severity: normal
stage: test needed
status: open
title: vars() manipulation encounters problems with Enum
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31801>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to