pyvec / naucse.python.cz

Website with learning materials / Stránka s učebními materiály
https://naucse.python.cz
Other
320 stars 117 forks source link

intro/magic: OrderedEnum is obsolete #305

Open encukou opened 6 years ago

encukou commented 6 years ago

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 commented 6 years ago

cc @hroncok

hroncok commented 6 years ago

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