naucse.python.cz icon indicating copy to clipboard operation
naucse.python.cz copied to clipboard

intro/magic: OrderedEnum is obsolete

Open encukou opened this issue 6 years ago • 2 comments

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.

encukou avatar Jan 03 '18 14:01 encukou

cc @hroncok

encukou avatar Jan 03 '18 14:01 encukou

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__.

hroncok avatar Jan 03 '18 14:01 hroncok