-
-
Notifications
You must be signed in to change notification settings - Fork 404
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
Inconsistent SopelMemory behavior with Identifier keys & lookups by string #1341
Comments
Looks like a "|" in the nickname also trips it up. Running bot.users.get("nick|name") doesn't find the user, it works with nicks that do not contain the pipe character. |
I wonder if that's the same issue… Now that I take a close look at what Fixing it wouldn't help with this, though, even if it really is doing the wrong thing. It'd just make e.g. |
Good shout! Using str.replace("|","\") on the nickname before getting it works! |
In the interest of getting 6.6.0 out sooner—it's already taken a month longer than I hoped—I'm punting this fix. Jumped the gun on changing the milestone, though, since the planned change should also be mentioned in the changelog along with #1389. |
Changelog drafted; milestone reminder no longer needed. |
Re-prioritizing stuff for 7.0 |
🥳 |
Looking up a
unicode
/str
key that is not all-lowercase in aSopelMemory
(dict) that usesIdentifier
s as keys works inconsistently. For example,'Sopel' == Identifier('Sopel')
, but as far asSopelMemory.__contains__()
is concerned it's not equal.The cause is,
unicode
/str
objects are case sensitive when hashed, whereasIdentifier
always returnsself._lowered.__hash__()
. Among other things, this affects theip
module looking up hostnames by nick (as string) frombot.users
without casting toIdentifier
first (functionality introduced in #1033).I can think of two solutions. One is just always casting to
Identifier
when indexing dictionaries by nickname (or channel name), but that's not as batteries-included as I'd like. The other solution, which I'm toying with, is creating a subclass ofSopelMemory
that's designed for usingIdentifier
s as keys, and always normalizes everything. Call it anIdentifierMemory
orIdict
(Sopel already has aDdict
), for now. (Other ideas are welcome, as always.)I'd like to get this resolved for 6.6.0, ideally. It's already been "broken" for some time, just patched around in my (and presumably others') modules by always manually casting string inputs to
Identifier
when needed. I don't think those manual casts should be necessary.Thoughts on what direction to take
SopelMemory
could be re-implemented as an extension ofcollections.MutableMapping
, since extendingdict
might not be the best idea. As Jochen Ritzel says there, what we really need is the interface of adict
. What's under the hood doesn't matter that much. Abstract base classes are available from Python 2.6 and up, so this option is safe on the compatibility front. The main concern with it is performance—thedict
built-in type is generally implemented in lower-level code (for example, C in CPython implementations), and defining a custom class in Python would mean slower operations on the object.I'm going to also investigate overriding more of
dict
to get the desired behavior, of course. It would be ideal to preserve as much performance as possible. Just haven't looked deep enough into that path yet; focused on too many other things.The text was updated successfully, but these errors were encountered: