Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

So can I declare an enum value to be e.g. a list? Is that value "frozen" when the enum declaration is processed or what?


A list is not a value, it is a type of object. The second to last paragraph of the section in the reference manual I linked may help:

  Some objects contain references to other objects; these are called
  containers. Examples of containers are tuples, lists and dictionaries. The
  references are part of a container’s value. In most cases, when we talk
  about the value of a container, we imply the values, not the identities of
  the contained objects; however, when we talk about the mutability of a
  container, only the identities of the immediately contained objects are
  implied. So, if an immutable container (like a tuple) contains a reference
  to a mutable object, its value changes if that mutable object is changed.
PEP-435 says enums are bound to "unique, constant values" -- not that you can bind enums to arbitrary types of objects.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: