isupport: parse CLIENTTAGDENY to a custom type that understands *#2714
isupport: parse CLIENTTAGDENY to a custom type that understands *#2714
*#2714Conversation
This replaces directly passing through the CLIENTTAGDENY value as a plain string. Consumers of the CLIENTTAGDENY token can either check whether a tag name is directly contained in the set, or go through the `is_denied()` method to apply wildcard logic if appropriate. The `ClientTagDeny` object's membership tests are case insensitive.
|
I get the idea. I'm trying to think about the use case:
I don't think you really need to implement all the magic methods, I'd replace them with this instead: class ClientTagDenied:
def __init__(self, *tags: str) -> None:
self.tags = frozenset(...)
def is_denied(self, tag: str) -> bool:
"""Tell if tag is denied."""
...
def all(self, *tags: str) -> bool:
"""Tell if all tags are denied, not just some of them."""
...
def any(self, *tags: str) -> bool:
"""Tell if at least one tag is denied."""
...I think you could keep more or less your unit tests - except for the case-insensitive comparison. I think it's an OK tradeoff, given the niche usage for that information. What do you think? |
|
I am trying to keep the interface simple, using the Also oops: Tag names MUST be treated as "case-sensitive opaque identifiers", so the case-insensitive comparison I added for convenience is spec-breaking. Making the object read-only makes sense to me. It works as long as a plugin doesn't grab and hold a long-lived reference to it (since the server can re-advertise the CLIENTTAGDENY token if its configuration changes). I don't have the energy to do it right now, but this needs a rewrite with a closer eye to the spec. (Another example: |
The more I think about the issue, the more I think the bot itself should be the one dealing with allowed/denied tags, and offer a convenient interface, and less ISUPPORT itself. But for that, I need to pursue my exploration of implementing client-only tag in Sopel... and I've barely touched the surface so far.
Exactly like anything that is in ISUPPORT: a plugin shall not make a copy and use that as a reference, since it can change at anytime. |
Counter: The bot shouldn't have an infinitely expanding API surface. I will entertain the idea that This could be (almost-)3am-brain talking… Yet sometimes I think it's odd that we've added things like |
This replaces directly passing through the CLIENTTAGDENY value as a plain string.
Consumers of the CLIENTTAGDENY token can either check whether a tag name is directly contained in the set, or go through the
is_denied()method to apply wildcard logic if appropriate.The
ClientTagDenyobject's membership tests are case insensitive.Resolves #2501 in, possibly, "overkill" fashion. I like offering plugin authors some convenience, but I'll understand if it would be preferred to just use a simple list or set.
Checklist
make qa(runsmake lintandmake test)