Message304487
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. |
|
Date |
User |
Action |
Args |
2017-10-17 00:21:55 | ethan.furman | set | recipients:
+ ethan.furman, barry, eli.bendersky |
2017-10-17 00:21:55 | ethan.furman | set | messageid: <1508199715.37.0.213398074469.issue31801@psf.upfronthosting.co.za> |
2017-10-17 00:21:55 | ethan.furman | link | issue31801 messages |
2017-10-17 00:21:53 | ethan.furman | create | |
|