What is a function parameter =[] for?

Chris Angelico rosuav at gmail.com
Fri Nov 20 11:36:28 EST 2015


On Sat, Nov 21, 2015 at 3:29 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Fri, Nov 20, 2015 at 9:24 AM, Chris Angelico <rosuav at gmail.com> 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.

Which would make it like dict.__getitem__ and dict.get, which leads to
a lot of people using dict.get() because they don't know about
subscripting. And then they mask potential errors because they're
using the version that suppresses them, since they didn't even know
about the other. Not sure that's an improvement. But I do see the
logic in the separation.

ChrisA



More information about the Python-list mailing list