frozenset() without arguments should return a singleton
Terry Reedy
tjreedy at udel.edu
Fri Feb 11 17:50:11 EST 2005
"Stefan Behnel" <stefan.behnel-n05pAM at web.de> wrote in message
news:cuj06r$ep5$1 at lnx107.hrz.tu-darmstadt.de...
> Hi!
>
> frozenset() doesn't behave as the other immutable empty data types in
> 2.4:
>
> .>>> '' is ''
> True
> .>>> () is ()
> True
I believe the reference manual describes this sort of behavior for
immutables as an *optional* optimization. 0 is 0 and has been since at
least 1.3. I am not sure both of your statements above have been true as
long, but I not longer have 1.3 to check ;-).
> .>>> frozenset() is frozenset()
> False
> frozenset() called without arguments (or on empty sequences)
> should always return a singleton object.
If we interpret 'should' as 'preferably by me', ok.
>It is immutable, so I can't see a reason why it should take up more
>resources than necessary.
It will take some programmer's time to add the special case check and run
the test suite, and check in the changes. Yours? And perhaps some
execution time for each frozenset call. Since frozenset is not much used,
and multiple empty frozensets very rare, and the difference mostly
invisible, the frozenset implementor probably went on to other things.
Terry J. Reedy
More information about the Python-list
mailing list