[issue33235] Better help text for dict.setdefault

2020-10-03 Thread Inada Naoki


Change by Inada Naoki :


--
resolution:  -> out of date
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33235] Better help text for dict.setdefault

2020-10-03 Thread Irit Katriel


Irit Katriel  added the comment:

The help message is now:

  Help on method_descriptor:
  setdefault(self, key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.

This issue should be closed as out of date.

--
nosy: +iritkatriel

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33235] Better help text for dict.setdefault

2018-04-06 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

Changing docstring can break existing code, therefore it should go only in 
future new Python version unless it contains a bug. The current docstring in 
3.6 doesn't look incorrect to me. The docstring in 3.7 is different.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33235] Better help text for dict.setdefault

2018-04-06 Thread Éric Araujo

Éric Araujo  added the comment:

Note that if we switch the order like you propose, we don’t need to use 
dict.get:


  set D[k]=d if k not in D then return D[k]


I suspect the current doc was written the way it is because it matches the 
actual implementation.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33235] Better help text for dict.setdefault

2018-04-06 Thread Éric Araujo

Éric Araujo  added the comment:

The two lines are equivalent!

`d.setdefault(key, default)` does return the same thing as `d.get(key, 
default)`, and then sets `d[key] = default` if the get method went into the 
“key was not found, let’s return default” branch.

--
nosy: +eric.araujo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33235] Better help text for dict.setdefault

2018-04-06 Thread Paddy McCarthy

New submission from Paddy McCarthy :

Hi, I was answering some question and used dict.setdefault as part of the 
solution and posted the help() on it as part of my answer.

The help was this:

In [15]: help(mapper.setdefault)
Help on built-in function setdefault:

setdefault(...) method of builtins.dict instance
D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D

This seems the wrong way around. Is it not better expressed as

D.setdefault(k[,d]) -> set D[k]=d if k not in D and then D.get(k,d)

--
assignee: docs@python
components: Documentation
messages: 315015
nosy: Paddy McCarthy, docs@python
priority: normal
severity: normal
status: open
title: Better help text for dict.setdefault
type: enhancement
versions: Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com