naucse.python.cz
naucse.python.cz copied to clipboard
intro/magic: OrderedEnum is obsolete
Starting from 3.7, dicts will be guaranteed to be ordered. They're also ordered in CPython 3.6 (and PyPy, and there aren't other relevant 3.6 implementations). So, ordering will now come for free.
3.5 compat is still important, but it doesn't make a good example.
cc @hroncok
We mentioned those facts when explaining the thing. But yes, we might need a better example.
Idea: The real enum._EnumDict
does something about multiple definitions, i.e. it raises TypeError
when one attempts to redefine a value:
class FooEnum(Enum):
a = 1
a = 2
We might show that as an example. I.e. subclass a dict and prevent item reassignment in ___setitem__
.