Designing a hashable class that is implemented with a list
My `class State` is *conceptually* immutable, but *technically* mutable. In other words, I intend the instances of `State` to never change, but I implement `State` as a regular user-defined class, hence of course technically it can be modified.

Note: I am aware of the [cool recipes][1] to make a user-defined class technically immutable, but I wasn't planning to use them for the time being.

Note: strictly speaking, at the conceptual level, my class is "deep" immutable (is there a better word for it?). That is, I do not intend to modify anything contained (directly or indirectly) in its instances. By comparison, `tuple` or `frozenset` are only "shallow" immutable.

One of the attributes in `class State` is a list-like structure. I have a slight preference for a list, since during the construction of an instance, I want to be able to append things, swap elements in-place, etc. Of course, once the instance is fully built, I won't touch the attribute.

I have to make `State` hashable, so I would need to write a custom `__hash__` function for the list contained in it. Is it bad from a design or performance perspective?

I would argue that it's not bad design, since `State` is technically mutable anyway, and adding another technically mutable element to it won't make a difference. Its immutability depends on my code rather than any technical safeguard. Am I right?

I don't know about performance though. The following may be slow:

    class State:
      def __init__(self, *args):
        # ...
      def __hash__(self):
        return hash(tuple(self.list_attribute))

Moreover, now I am thinking of deriving `State` from a `list` or a `tuple`, since the `list` API is perfect for `State` instances (slicing, indexing, etc.). If I do that, using `tuple` is now completely impossible since I wouldn't be able to change it from `__init__` (and I cannot use `__new__`, since I want to assign some instance attributes before I set the tuple values, and those instance attributes aren't accessible from `__new__`). 

If I follow this approach I don't know how to define the `__hash__` function. How do I access the list values in the base object?

The following won't work since of course list isn't hashable:

    class State(list):
      # ...
      def __hash__(self):
        return hash((self.other_attribute, super().__hash__(self)))



  [1]: http://stackoverflow.com/questions/4828080/how-to-make-an-immutable-object-in-python
Designing a hashable class that is implemented with a list
===

My `class State` is *conceptually* immutable, but *technically* mutable. In other words, I intend the instances of `State` to never change, but I implement `State` as a regular user-defined class, hence of course technically it can be modified.

Note: I am aware of the [cool recipes][1] to make a user-defined class technically immutable, but I wasn't planning to use them for the time being.

Note: strictly speaking, at the conceptual level, my class is "deep" immutable (is there a better word for it?). That is, I do not intend to modify anything contained (directly or indirectly) in its instances. By comparison, `tuple` or `frozenset` are only "shallow" immutable.

One of the attributes in `class State` is a list-like structure. I have a slight preference for a list, since during the construction of an instance, I want to be able to append things, swap elements in-place, etc. Of course, once the instance is fully built, I won't touch the attribute.

I have to make `State` hashable, so I would need to write a custom `__hash__` function for the list contained in it. Is it bad from a design or performance perspective?

I would argue that it's not bad design, since `State` is technically mutable anyway, and adding another technically mutable element to it won't make a difference. Its immutability depends on my code rather than any technical safeguard. Am I right?

I don't know about performance though. The following may be slow:

    class State:
      def __init__(self, *args):
        # ...
      def __hash__(self):
        return hash(tuple(self.list_attribute))

Moreover, now I am thinking of deriving `State` from a `list` or a `tuple`, since the `list` API is perfect for `State` instances (slicing, indexing, etc.). If I do that, using `tuple` is now completely impossible since I wouldn't be able to change it from `__init__` (and I cannot use `__new__`, since I want to assign some instance attributes before I set the tuple values, and those instance attributes aren't accessible from `__new__`). 

If I follow this approach I don't know how to define the `__hash__` function. How do I access the list values in the base object?

The following won't work since of course list isn't hashable:

    class State(list):
      # ...
      def __hash__(self):
        return hash((self.other_attribute, super().__hash__(self)))



  [1]: http://stackoverflow.com/questions/4828080/how-to-make-an-immutable-object-in-python