I'm defining a Python object as being "immutable at any depth" iff
- it is (nominally) immutable; and
- if it is a "container" object, then it contains only objects that are "immutable at any depth";
For example ((1, 2), (3, 4))
is immutable at any depth, whereas ((1, 2), [3, 4])
isn't (even though the latter, by virtue of being a tuple, is "nominally" immutable).
Is there a reasonable way to test whether a Python object is "immutable at any depth"?
It is relatively easy to test for the first condition (e.g. using collections.Hashable
class, and neglecting the possibility of an improperly implemented __hash__
method), but the second condition is harder to test for, because of the heterogeneity of "container" objects, and the means of iterating over their "contents"...
Thanks!