Re: [Python-Dev] setdefault's second argument

2005-09-02 Thread Tim Peters
[Tim Peters] >> Dang! I may have just found a use, in Zope's >> lib/python/docutils/parsers/rst/directives/images.py (which is part >> of docutils, not really part of Zope): >> >> figwidth = options.setdefault('figwidth') >> figclass = options.setdefault('figclass') >> del options['fig

Re: [Python-Dev] setdefault's second argument

2005-08-31 Thread Tony Meyer
> To save you from following that link, to this day I still mentally > translate "setdefault" to "getorset" whenever I see it. I read these out of order (so didn't see the giveaway getorsetandget) and spent some time wondering what an "orset" was. I figured it must be some obscure CS/text process

Re: [Python-Dev] setdefault's second argument

2005-08-30 Thread David Goodger
[Tim Peters] > Dang! I may have just found a use, in Zope's > lib/python/docutils/parsers/rst/directives/images.py (which is part > of docutils, not really part of Zope): > > figwidth = options.setdefault('figwidth') > figclass = options.setdefault('figclass') > del options['figwidth']

Re: [Python-Dev] setdefault's second argument

2005-08-30 Thread Barry Warsaw
On Tue, 2005-08-30 at 16:46, Fredrik Lundh wrote: > But I stumbled upon this little naming protocol > > Protocol: if you have a suggestion for a name for this function, mail > it to me. DON'T MAIL THE LIST. (If you mail it to the list, that > name is disqualified.) Don't explain me

Re: [Python-Dev] setdefault's second argument

2005-08-30 Thread Fredrik Lundh
Tim Peters wrote: >> Anyone remember why nobody managed to come up with a better name >> for setdefault (which is probably the worst name ever given to a method >> in the standard Python distribution) ? > > I suggested a perfect name at the time: > >http://mail.python.org/pipermail/python-dev/

Re: [Python-Dev] setdefault's second argument

2005-08-30 Thread Tim Peters
[Fredrik Lundh] > ... > Anyone remember why nobody managed to come up with a better name > for setdefault (which is probably the worst name ever given to a method > in the standard Python distribution) ? I suggested a perfect name at the time: http://mail.python.org/pipermail/python-dev/2000-

Re: [Python-Dev] setdefault's second argument

2005-08-30 Thread Barry Warsaw
On Tue, 2005-08-30 at 14:53, Fredrik Lundh wrote: > Some kind of symmetry with get, probably. if > > d.get(x) > > returns None if x doesn't exist, it makes some kind of sense that > > d.setdefault(x) I think that's right, and IIRC the specific detail about the optional second argument

Re: [Python-Dev] setdefault's second argument

2005-08-30 Thread Wolfgang Lipp
On Tue, 30 Aug 2005 20:55:45 +0200, Tim Peters <[EMAIL PROTECTED]> wrote: > [Wolfgang Lipp] >> reminds me of dict.get()... i think in both cases being explicit:: >> >> beast = d.setdefault( 666, None ) >> ... > > Do you actually do this with setdefault()? well, actually more like::

Re: [Python-Dev] setdefault's second argument

2005-08-30 Thread Fredrik Lundh
Tim Peters wrote: > Anyone remember why setdefault's second argument is optional? Some kind of symmetry with get, probably. if d.get(x) returns None if x doesn't exist, it makes some kind of sense that d.setdefault(x) returns None as well. Anyone remember why nobody managed to come u

Re: [Python-Dev] setdefault's second argument

2005-08-30 Thread Tim Peters
[Wolfgang Lipp] > reminds me of dict.get()... i think in both cases being explicit:: > > beast = d.setdefault( 666, None ) > beast = d.get( 666, None ) > > just reads better, allthemore since at least in my code what comes > next is invariably a test 'if beast is None:...'. so > > beast

Re: [Python-Dev] setdefault's second argument

2005-08-30 Thread Wolfgang Lipp
On Tue, 30 Aug 2005 18:14:55 +0200, Tim Peters <[EMAIL PROTECTED]> wrote: d = {} d.setdefault(666) d > {666: None} > > just doesn't seem useful. In fact, it's so silly that someone calling > setdefault with just one arg seems far more likely to have a bug in > their code than to g

Re: [Python-Dev] setdefault's second argument

2005-08-30 Thread Tim Peters
[Raymond] > setdefault() described it as behaving like dict.get() but inserting the > key if not found. ... > Likewise, I found zero occurrences in the library, in my cumulative code > base, and in the third-party packages on my system. [Tim] >> If there isn't a sane use case for leaving the sec

Re: [Python-Dev] setdefault's second argument

2005-08-30 Thread Raymond Hettinger
[Tim] > Anyone remember why setdefault's second argument is optional? IIRC, this is a vestige from its ancestor. The proposal for setdefault() described it as behaving like dict.get() but inserting the key if not found. > Haven't found > any 1-arg uses of setdefault() either, except for test c

Re: [Python-Dev] setdefault's second argument

2005-08-30 Thread Tim Peters
[Tim Peters] >> Anyone remember why setdefault's second argument is optional? >> >> >>> d = {} >> >>> d.setdefault(666) >> >>> d >> {666: None} >> ... [Josiah Carlson] > For quick reference for other people, d.setdefault(key [, value]) > returns the value that is currently there, or just assigne

Re: [Python-Dev] setdefault's second argument

2005-08-30 Thread Josiah Carlson
Tim Peters <[EMAIL PROTECTED]> wrote: > > Anyone remember why setdefault's second argument is optional? > > >>> d = {} > >>> d.setdefault(666) > >>> d > {666: None} For quick reference for other people, d.setdefault(key [, value]) returns the value that is currently there, or just assigned. T

[Python-Dev] setdefault's second argument

2005-08-30 Thread Tim Peters
Anyone remember why setdefault's second argument is optional? >>> d = {} >>> d.setdefault(666) >>> d {666: None} just doesn't seem useful. In fact, it's so silly that someone calling setdefault with just one arg seems far more likely to have a bug in their code than to get an outcome they actual