-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
core: URL Callbacks new interface #1508
Conversation
You can forge on ahead with a new PR branch based on this one, like you've done before, unless you need to discuss direction (in #1489) first. That way, no matter how much bikeshedding happens with replacing the url module, we'll have a clean new interface (this PR) in the bag. I like that this really is just adding convenience methods to do what plugins already do, so nothing will break (yet) if module code isn't updated. 😁 Do you think it's worth checking in the register/unregister functions added here whether the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Request changes" because it looks like some of what you intended to do in the docstrings is broken (see line notes).
While you're looking at those, maybe also think about (as I said in a "real" comment earlier tonight) whether validating the pattern is worthwhile. I just expect that Bad Things™ might happen if some enterprising coder passes in a string instead of a compiled re
object—even if said Bad Things™ are just callbacks that don't trigger.
I knew you would understand. 👍
Yeah, I was wondering too. It's not that complicated, I'll do that. |
Also: of course I failed at docstring again. x) |
0685b81
to
cdc48fa
Compare
Hm. I'm not sure "re-request a review" was the right idea. Meh, I guess I need to learn what the new github has to offer with all these features. Anyway @dgw I fixed the docstrings and added the safety measures to check if pattern is a compiled regex. |
Ahem. Checkstyle? Edit: also tests are broken because of course they are. Mock objects are the worst. :( |
cdc48fa
to
7e35d5b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay, I'm not the only one who gets bitten by checkstyle after pushing! 😁
It's nitpick-docstrings-o'clock again, lol.
And to search for URL matching patterns to get these callbacks: * `bot.register_url_callback(regex, callback)`, to register a `callback` to call when a URL matches `regex` * `bot.unregister_url_callback(regex)` to remove this regex from triggering callbacks * `bot.search_url_callbacks(url)` to get a list of (callback, match) for each pattern matched by the URL This provides a unified interface to work with URL Callbacks, but does not change how the built-in url plugin works (yet).
7e35d5b
to
2c81f72
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, with the caveat that the additions to test_tools.MockSopel
will be temporary until we find a way to run tests on the "real" Sopel class instead of a mocked-up version.
Merging so @Exirel can properly get started on a PR to fix the mess that is |
This new interface adds:
bot.register_url_callback(regex, callback)
, to register acallback
to call when a URL matchesregex
bot.unregister_url_callback(regex)
to remove this regex from triggering callbacksbot.search_url_callbacks(url)
to get a list of (callback, match) for each pattern matched by the URLThis provides a unified interface to work with URL Callbacks, but does not change how the built-in url plugin works (yet).
So this:
Become this:
It does not change the fact that the
url
built-in plugin is required at the moment in order to work with URL Callback (see #1489 for that).@dgw now my question is, should I keep moving forward, and replace the
url
built-in plugin? Or should we merge this PR as-is, and work from there in another PR?