-
-
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
Importing callables from other plugins silently duplicates bot commands #2488
Comments
To make the workaround explicit: Avoiding this is as simple as doing e.g. |
@Exirel points out that we can't look at |
It's like what I said earlier on IRC about "or a submodule"—but with more nuance, I guess? Plugins that import different commands from submodules of themselves to build the "real" plugin file that Sopel loads were what I had in mind. 😁 |
To report and to extend on what I said on IRC: I'm not sure to see an issue to resolve here, and I don't think solving said issue would be a good idea, especially given the complexity of the problem. Sopel makes no promise about plugin's interdependence, but it promises that a plugin callable exposed by a plugin will be loaded for that plugin (note that I say "exposed" here, and not "defined"). Where the plugin callable is defined is never considered. If you think that way, then you understand that Sopel does exactly what is asked: you expose a plugin callable? It'll be loaded for that plugin. Here is the catch: we can't ensure loading order. Because Sopel makes no promise on interdependence, Sopel also makes no promise on loading order! So we really can't know if a plugin is the "legitimate owner" of a callable, unless we are willing to control a bit too much on Python's internal loading machinery. That's why I'm really not into this. I'd rather help people to craft better reusable code for their plugin, and be a bit more conscious about what they are doing, than trying to solve the problem for them by throwing more code at it. I think #2489 is a good first step, another step would be to write that "create your own plugin" tutorials I'm thinking about (since forever, I should have done it already). |
Description
The loader machinery treats Sopel callables in a plugin as belonging to that plugin even if the callable is imported from another plugin, which can result in duplication of a command when one plugin is importing from another.
Reproduction steps
I discovered this while writing a plugin that aliases the command
w
towp
This "unboxing" of the callable from the original plugin can lead to duplication of the
wp
command.Expected behavior
The loader should be able to distinguish between callables that are indigenous to a plugin and callables that came from somewhere else, by comparing the
__module__
attribute of the callable against the plugin module under consideration.It is probably too disruptive to skip callables that came from somewhere else (users may be relying on this behavior), but the core could issue a warning about this to make the failure marginally less mysterious.
Relevant logs
No response
Notes
No response
Sopel version
6af4f23
Installation method
pip install
Python version
3.9.16
Operating system
Ubuntu 20.04
IRCd
No response
Relevant plugins
No response
The text was updated successfully, but these errors were encountered: