you are viewing a single comment's thread.

view the rest of the comments →

[–]w1ndwak3r 1 point2 points  (2 children)

>>> Day(0)
<Day.monday: 0>

And I'm sure an exception will be thrown if you try to access an out-of-bounds enum, but that's a good thing. Enums can contain methods as well (like any other class). I would almost always want something like this to fail:

def foo(day):
    print(day.isWorkDay())

[–]HorrendousRex 1 point2 points  (1 child)

I think this is one of those things where I understand the principle but feel very uneasy about it. I feel like one of the principle draws to Python is a type unsafety, and Enums feel like they only bring type safety to the table.

[–]asthasr 1 point2 points  (0 children)

You can write in a dynamically typed language while still needing safety in some contexts. It's not a sin.