[Python-ideas] function defaults and an empty() builtin

Steven D'Aprano steve at pearwood.info
Sat May 21 05:19:49 CEST 2011


On Sat, 21 May 2011 05:18:30 am Masklinn wrote:
> Why special-case empty lists when there is no need to?

That's a remarkable statement. What is empty() except a special case for 
empty lists?

If you and Jack are serious about this proposal, it would require at 
least two such functions, emptylist and emptydict, not just empty(). 
And even if you are right that it solves the problem of default=[] 
(which you aren't, but for the sake of the argument lets pretend), it 
doesn't solve the general issue of mutable defaults.

As I said, having a freeze() function that creates an immutable list 
might be a good idea, although not for the default argument issue. (I'm 
not entirely sure how that differs from tuple, but that's another 
issue...) But special casing a frozen empty list seems silly, and the 
use-case given by the OP, and defended by you, is actively harmful.



-- 
Steven D'Aprano



More information about the Python-ideas mailing list