Author josh.r
Recipients BTaskaya, Mark.Shannon, christian.heimes, josh.r, mark.dickinson, pablogsal, rhettinger, serhiy.storchaka, terry.reedy
Date 2020-11-30.18:46:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Yep, Mark Shannon's solution of contextual hashing is what I was trying (without success) when my last computer died (without backing up work offsite, oops) and I gave up on this for a while. And Batuhan Taskaya's note about compiler dictionaries for the constants being a problem is where I got stuck.

Switching to lists might work (I never pursued this far enough to profile it to see what the performance impact was; presumably for small functions it would be near zero, while larger functions might compile more slowly).

The other approach I considered (and was partway through implementing when the computer died) was to use a dict subclass specifically for the constants dictionaries; inherit almost everything from regular dicts, but with built-in knowledge of slices so it could perform hashing on their behalf (I believe you could use the KnownHash APIs to keep custom code minimal; you just check for slices, fake their hash if you got one and call the KnownHash API, otherwise, defer to dict normally). Just an extension of the code.__hash__ trick, adding a couple more small hacks into small parts of Python so they treat slices as hashable only in that context without allowing non-intuitive behaviors in normal dict usage.
Date User Action Args
2020-11-30 18:46:42josh.rsetrecipients: + josh.r, rhettinger, terry.reedy, mark.dickinson, christian.heimes, Mark.Shannon, serhiy.storchaka, pablogsal, BTaskaya
2020-11-30 18:46:42josh.rsetmessageid: <>
2020-11-30 18:46:42josh.rlinkissue42454 messages
2020-11-30 18:46:42josh.rcreate