frozenset() without arguments should return a singleton

Stefan Behnel stefan.behnel-n05pAM at web.de
Fri Feb 11 14:10:54 EST 2005


Hi!

frozenset() doesn't behave as the other immutable empty data types in 2.4:

.>>> '' is ''
True
.>>> () is ()
True
.>>> frozenset() is frozenset()
False

.>>> id(()),id(())
(1077579820, 1077579820)
.>>> id(())
1077579820
.>>> id(frozenset()),id(frozenset())
(1077581296, 1077581296)
.>>> id(frozenset())
1077581440
.>>> id(frozenset(()))
1077582256

frozenset() called without arguments (or on empty sequences) should always
return a singleton object. It is immutable, so I can see no reason why it
should take up more resources than necessary.

Stefan



More information about the Python-list mailing list