Thoughts on new vs traditional idioms

Peter Otten __peter__ at
Tue Mar 2 18:13:44 CET 2004

Jeff Epler wrote:

> On Tue, Mar 02, 2004 at 03:48:19PM +0100, Peter Otten wrote:
>> Do you have a class with immutable instances handy where the following
>> assertion fails?
>> assert immutableObj.__class__(immutableObj) is immutableObj
> Python 2.3.2 (#1, Oct 17 2003, 10:41:07)
>>>> import sets
>>>> ii = sets.ImmutableSet([1,2,3])
>>>> ii.__class__(ii) is ii
> False

You win :-) 

Now I think about it (again), the above is the behaviour to be expected for
every immutable class (at least if it's implemented in Python, don't know
about C) that predates the advent of __new__().

By the way, is ImmutableSet meant to stay? In the 1.4 setobject.c code there
is a frozenset which _has_ the "do I really need to copy" check:

if (iterable != NULL && PyFrozenSet_CheckExact(iterable)) {
    return iterable;


More information about the Python-list mailing list