[issue46925] Document dict behavior when setting equal but not identical key

2022-03-07 Thread Jarek Potiuk


Jarek Potiuk  added the comment:

Yeah. Sounds like adding docs is indeed needed :)

--

___
Python tracker 

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



[issue46925] Document dict behavior when setting equal but not identical key

2022-03-06 Thread Inada Naoki


Inada Naoki  added the comment:

I don't know much about Java, but Java's WeakHashMap is same to Python's 
WeakKeyDictionary.

https://docs.oracle.com/javase/9/docs/api/java/util/WeakHashMap.html

"""
This class is intended primarily for use with key objects whose equals methods 
test for object identity using the == operator. Once such a key is discarded it 
can never be recreated, so it is impossible to do a lookup of that key in a 
WeakHashMap at some later time and be surprised that its entry has been 
removed. This class will work perfectly well with key objects whose equals 
methods are not based upon object identity, such as String instances. With such 
recreatable key objects, however, the automatic removal of WeakHashMap entries 
whose keys have been discarded may prove to be confusing.
"""

--
nosy: +methane

___
Python tracker 

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



[issue46925] Document dict behavior when setting equal but not identical key

2022-03-06 Thread Malthe Borch


Malthe Borch  added the comment:

Java's HashMap has also the (current) Python behavior. An existing same key is 
not replaced.

--

___
Python tracker 

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



[issue46925] Document dict behavior when setting equal but not identical key

2022-03-05 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

The weakref docs in particular should point out the OP's example and highlight 
the workaround.

--

___
Python tracker 

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



[issue46925] Document dict behavior when setting equal but not identical key

2022-03-05 Thread Jelle Zijlstra


Jelle Zijlstra  added the comment:

Agree, I couldn't find a place where this behavior is documented. The second 
paragraph in 
https://docs.python.org/3.10/library/stdtypes.html#mapping-types-dict comes 
close. Reopening as a documentation issue.

--
assignee:  -> docs@python
components: +Documentation -Library (Lib)
nosy: +docs@python
resolution: rejected -> 
stage: resolved -> needs patch
status: closed -> open
title: Replace key if not identical to old key in dict -> Document dict 
behavior when setting equal but not identical key
versions: +Python 3.10, Python 3.11, Python 3.9

___
Python tracker 

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