PLUGINS = {}: register(name, func) stores func under name in PLUGINS and returns None; run_plugin(name, *args, **kwargs) looks up name in PLUGINS and calls it with the given args/kwargs, returning its result (or the string "No such plugin" if name is not registered); list_plugins() returns a sorted list of all registered plugin names.def hello(who): return f"Hello, {who}"
register("hello", hello)
run_plugin("hello", "World")Hello, World
run_plugin looks up "hello" in PLUGINS and calls it with "World".
list_plugins()
['hello']
Only "hello" has been registered so far, sorted alphabetically (trivially, with one element).
run_plugin("missing")No such plugin
"missing" was never registered.
register mutates the shared dict, so it does not need the global keyword (it is not reassigning PLUGINS itself).
run_plugin should use PLUGINS.get(name) and check for None before calling, then call func(*args, **kwargs) to forward all arguments.