Message226491
I found one thing which you can't do subclassing Enum what you can with metaclasses:
enforcing type checking at class creation time. Values are passed to __new__ as positional arguments, so it's impossible to tell the difference between these two:
class SingleValue(MultiVAlueEnum):
one = 1, 'one'
two = 2
class Tuple(MultiVAlueEnum):
one = 1, 'one'
two = 2,
because in both cases (2,) would be passed. It's not a big deal, but "Explicit is better than implicit." and also I would like to avoid typos, which I often make like this:
class StrValues(MultiValueEnum):
one = ('One'
'one')
two = ('two',
'Two')
In this case, the first member would be accepted as 'Oneone' instead of ('One', 'one') and I see no way to check that without metaclasses. Do you? |
|
Date |
User |
Action |
Args |
2014-09-06 14:26:25 | kissgyorgy | set | recipients:
+ kissgyorgy, barry, eli.bendersky, ethan.furman |
2014-09-06 14:26:25 | kissgyorgy | set | messageid: <1410013585.45.0.904286108748.issue22339@psf.upfronthosting.co.za> |
2014-09-06 14:26:25 | kissgyorgy | link | issue22339 messages |
2014-09-06 14:26:25 | kissgyorgy | create | |
|