launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #06584
[Merge] lp:~jtv/maas/enum into lp:maas
The proposal to merge lp:~jtv/maas/enum into lp:maas has been updated.
Description changed to:
This is something I needed for a branch I'm working on, but it also turned out to overlap with an existing factory method: enumerating an enum.
We may solve this by moving to a proper enum class later, but that involves bikeshedding over which one to use — and even then, it's not a given, perversely, that enumeration is a built-in functionality. So for now I'm hiding it all behind a simple but flexible function.
At its core, an enum is a dict. The things you may need to do with it are already in dict, or easily built on top: list keys, list values, look up item, sort by key or value. So the easiest way to provide flexible introspection is to map the enum into a dict. It may mean a tiny bit of extra work on top, e.g. "sort keys," but at least a map conversion reduces it to idiomatic standard-library-based code with a minimum of API.
To avoid silly mistakes, I added factory tests. It may seem overzealous to test things like getRandomBoolean, but we really did have a non-obvious bug in there due to insufficient test coverage. I wish I could test that full ranges are covered, but it's hard to test that reliably for random.
Once we start wanting richer enum functionality outside of tests, of course, we do need to worry about a better enum class. We probably don't want this to grow into Our Very Own Enum Implementation™.
Jeroen
For more details, see:
https://code.launchpad.net/~jtv/maas/enum/+merge/95846
--
https://code.launchpad.net/~jtv/maas/enum/+merge/95846
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/enum into lp:maas.
References