I have several functions that I'd like to operate on both mutable and immutable containers (mostly tuples vs. objects) and I'm looking for the optimal way to test for mutability in these objects. I can think of many ways to do this. For example:
try setattr: do mutable stuff except Error: do immutable replacements
I also considered adding a metaattribute to my classes based on mutability; however, this limits the usage of my functions to just the customized objects in my programs.
I could also make 2 functions, one for mutable and one for immutable objects, but then I get lots of extra code.
Does anyone know of a Pythonic, best way to think about this?