@abarnert The original problem was that given: x = []; x.append(x); ForcedHash(x) == ForcedHash(x) we get a RecursionError again. But I think the conclusion is that it just makes sense that the limitation of this class is the same as the ones of the == operator
I am also unsure why that suddenly got downvoted so hard
@OlivierMelançon Well, this is one of those “you almost always shouldn’t do this” questions, and a lot of people tend to downvote those unless you give a really good reason why you have an exception.
I disagree with he fact this one is a "almost always shouldn't" it is not the first time I implement a dict with mutable keys, it does have a lot of uses, especially performance-wise
And the design decision I ended up taking, by the way, is to simply let the exception be raised. One of the initial goals was to see if a list contains equal (possibly mutable) objects in O(n). Since [[...]] is simply not equatable, it makes sense for the algorithm to fail to handle.
As long as you can guarantee the lists aren’t mutated while the dict is alive, of course it’s reasonable. But in most such problems, the question is why not just use tuples. The reason I assumed you had an answer to that is that the people who asked the other 100 questions on how to use a list as a dict key wouldn’t have even been able to think of the problems you’d already solved.
But I think a lot of people don’t read carefully; they see the 101st question on hashing lists, no explanation for why you need to do it, and just downvote and move on.
Anyway, the most interesting remaining question to me is what made me think that d{x:0} == d{y:0} ought to return False for distinct self-containing x and y. I can't think of any good reason for that, and yet, before thinking about it, I was pretty sure that was the obvious right answer…
The exact reason I do not use tuple is because (1, 2, 3) != [1, 2, 3]. This information is lost when simply casting to the mutable equivalent type
The parallel between my code and deepcopy's memo seemed pretty clear to you. Since deepcopy is id based, I assume this is what made you think the objects should not be equal
@abarnert Did you really went on nesting a tuple in itself to see what would happen? That's pretty cool!
Yeah, but that's only for the underlying memo for catching self-recursive objects; it was pretty clear that just using id-hashing for the top-level dict wasn't going to solve your problem (or you would have just done that and saved yourself a lot of trouble). But maybe that's what misled me here…
Every time someone has a question about the C API, I tell them they should be using PyCxx or Cython or Pyd or rust-python, but when I want to slap something together, I run my silly makecboilerplate.py script and edit it manually, because I never listen to myself…
If your values are comparable, it's probably easier to just use a nice wide tree so it's technically logarithmic time but practically about as fast as a hash table.
blist, sortedcontainers, pyrsistent, whatever.
Oh, wait, you meant just equality-comparable, not totally-ordered, right?
I've never gotten to use it in a project for work, but for personal stuff, I use it quite a bit. I'm sometimes amazed at what it can optimize. And even after trying to read all the whitepapers and the source code (and I even worked on a tracing JIT for JavaScript/ActionScript…), I remained amazed. I suspect the truth is that Armin is a wizard.
Of course it is a bit annoying to drop back from Python 3.7 to 3.5.
There was one of those "I'll do an experimental fork if anyone will pay me" proposals, but $0. My conspiracy theory is that Guido threatened the break the kneecaps of anyone who contributed.
Although Armin spending his time on STM instead was a lot more interesting, even if that fork seems to be stagnant now.
Yeah, yield from. But also a lot of little things. Memory view, import hooks, stuff that made porting from 2.x a lot less painful (u prefixes, callable), and lots of optimizations (compact unicode strings, decimals that are almost fast enough to use, faster comprehensions on 64-bit systems, …).