Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: What is a function parameter =[] for? Date: Fri, 20 Nov 2015 18:41:42 +0200 Organization: A noiseless patient Spider Lines: 55 Message-ID: <87r3jkd3nd.fsf@elektro.pacujo.net> References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <877flcrh26.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="b7cb1518d23ec19d482dcc9c31d30fdd"; logging-data="21197"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7cQ9ijTen0hy8y5oh/Kpp" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:svRxikUHiz0ekvSCYts4iYr5JwQ= sha1:wbPoirGMHXEmIvGgX6CANhxFV6o= Xref: csiph.com comp.lang.python:99169 Ian Kelly : > On Fri, Nov 20, 2015 at 9:24 AM, Chris Angelico wrote: >> The cases where that's not true are usually ones that are more like >> C++ overloaded functions: >> >> def next(iter): >> return iter.__next__() >> def next(iter, default): >> try: return iter.__next__() >> except StopIteration: return default > > IMO the version with the default argument should have a different > name, as it is conceptually a different function. I don't necessarily disagree, but consider this function: socket.create_connection(address[, timeout[, source_address]]) It has been implemented: _GLOBAL_DEFAULT_TIMEOUT = object() def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=None): which is somewhat inconsistent. Why not: def create_connection(address, timeout=None, source_address=None): or: omitted = object() def create_connection(address, timeout=omitted, source_address=omitted): The argument for the former is that neither timeout nor source_address can meaningfully be None. The argument for the latter is that it follows a generic pattern that places no assumptions on the legality or illegality of None as a value. The chosen implementation allows: s.create_connection(address, source_address=None) but not: s.create_connection(address, timeout=None) Marko