[issue46925] Replace key if not identical to old key in dict

2022-03-05 Thread Jarek Potiuk


Jarek Potiuk  added the comment:

How about if we make PR instead to the documentation about this behaviour? 

I think this behaviour is a little surprising (you need to know the internals 
of how WeakKeyDict keys are constructed and checked) and while I understand you 
do not want breaking change, maybe this should be explained to the users and 
example given how to apply the workaround?

Just following the "least surprise" principle.

--
nosy: +potiuk

___
Python tracker 

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



[issue46925] Replace key if not identical to old key in dict

2022-03-04 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

I concur with Jelle and Methane that we can't do this without breaking code.

Also if you don't care about dict order, the work around is easy.  Just remove 
the old key:

d.pop(k); d[k] = v

--
nosy: +rhettinger
resolution:  -> rejected
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



[issue46925] Replace key if not identical to old key in dict

2022-03-04 Thread Jelle Zijlstra


Jelle Zijlstra  added the comment:

As @methane also said on the PR, this is a backward compatibility break and we 
can't just change the behavior. I'd be opposed to a change here: the proposed 
behavior isn't clearly better than the existing behavior (sometimes you want 
one behavior, sometimes another), and it will be difficult to find and adjust 
code that relies on the existing behavior.

--
nosy: +Jelle Zijlstra

___
Python tracker 

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



[issue46925] Replace key if not identical to old key in dict

2022-03-04 Thread Malthe Borch


New submission from Malthe Borch :

When a key that is equal to an existing key (but not the same object identity) 
is used to set a new value, the key itself is not replaced.

This manifests perhaps most clearly in `weakref.WeakKeyDictionary` where keys 
can mysteriously disappear.

Consider two equal keys, k1 and k2:

d = WeakKeyDictionary()
d[k1] = 1
d[k2] = 2
del k1

We would expect the dictionary to have a single entry k2 => 2. But in fact it 
is empty now.

--
components: Library (Lib)
messages: 414554
nosy: malthe
priority: normal
pull_requests: 29811
severity: normal
status: open
title: Replace key if not identical to old key in dict
type: behavior

___
Python tracker 

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