This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ethan.furman
Recipients barry, eli.bendersky, ethan.furman
Date 2017-10-17.00:21:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1508199715.37.0.213398074469.issue31801@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-10-17 00:21:55ethan.furmansetrecipients: + ethan.furman, barry, eli.bendersky
2017-10-17 00:21:55ethan.furmansetmessageid: <1508199715.37.0.213398074469.issue31801@psf.upfronthosting.co.za>
2017-10-17 00:21:55ethan.furmanlinkissue31801 messages
2017-10-17 00:21:53ethan.furmancreate