Chris Rebert <c...@rebertia.com> writes:

> On Thu, Oct 7, 2010 at 1:46 PM, Arnaud Delobelle <arno...@gmail.com> wrote:
[...]
>> I think defining mutability is subject to opinion, but here is a first
>> approximation.
>>
>>
>> def mutable(obj):
>>    return obj.__hash__ is None or type(obj).__hash__ == object.__hash__
>
> Corner case (I think):
>>>> a = object()
>>>> a.b = "c"
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: 'object' object has no attribute 'b'
>>>> mutable(a)
> True

Ah true.  There was also the problem that e.g. mutable(tuple) was False.

How about this second approximation:

def mutable(obj):
    h = type(obj).__hash__
    return not h or h is object.__hash__ and type(obj) is not object

-- 
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to