-
-
Notifications
You must be signed in to change notification settings - Fork 553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WeakValueDictionary does not handle unhashable keys correctly #15956
Comments
comment:1
Hm, unfortunate situation. In python 3 we'd be able to use |
comment:2
You are right. It is annoying to fix this in python2. I ran into it while working on #11895 (disable hashing of padics) btw. |
Branch: u/saraedum/ticket/15956 |
comment:5
The proposed fix is very elegant and minimal, but it does noticeably affect a code path that deserves to be very fast: testing that a key does not occur in the dictionary. Timings:
Compared with a normal dictionary:
The change from 122ms to 151ms is an increase of 25% in time taken (and this is for integers, which hash extremely quickly. I've also tried it with a string key '1', where I got 101ms vs. 127ms, so a penalty of around 30ms/10^7 seems to be expected). Of course, it's nice if We could of course patch python and backport For the current proposal, I'd like to see some real-world motivation to bring the error reporting in line with other dictionaries before I'd consider significantly degrading performance. A further problem with the current proposal: it only fixes one symptom. The nastier example http://hg.python.org/cpython/file/5cab0ada97b2/Objects/dictobject.c#l1046 (stack overflow during key comparison) isn't addressed by verifying that the key hashes. Going all the way with the New commits:
|
Commit: |
Changed branch from u/saraedum/ticket/15956 to u/nbruin/ticket/15956 |
comment:7
Turns out backporting The current implementation is actually a little faster than New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:9
PING I'm happy with Julian's doctests. The current use of |
Reviewer: Nils Bruin, ??? |
Author: Julian, Nils Bruin |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:11
Thanks for taking care of this :) |
Changed author from Julian, Nils Bruin to Julian Rueth, Nils Bruin |
Changed reviewer from Nils Bruin, ??? to Nils Bruin, Julian Rueth |
Changed branch from u/nbruin/ticket/15956 to |
The
WeakValueDictionary
behaves differently from regular dicts for unhashable keys:This is because http://docs.python.org/2/c-api/dict.html#PyDict_GetItem does not throw a
TypeError
.CC: @nbruin @simon-king-jena
Component: misc
Keywords: hash
Author: Julian Rueth, Nils Bruin
Branch/Commit:
52e02b1
Reviewer: Nils Bruin, Julian Rueth
Issue created by migration from https://trac.sagemath.org/ticket/15956
The text was updated successfully, but these errors were encountered: