
Boss
Boss: Plugin Registry

Boss Fight!
Every passing test breaks a shield.
The Lantern Guild's control console is a tangle of if statements.
Every new gadget means editing the console. The Archmage wants a
plugin system: drop in a class, and its commands simply appear.
The plugins are already written (see Lamp and Weather). Build the
machinery underneath them.
Assignment
command(func): a decorator that marks a method as a console command by settingfunc.is_command = True, then returnsfunc.Plugin.__init_subclass__(cls, name=None, **kwargs): registers each subclass inPlugin.registryundername, or under the lower-case class name if no name is given.Console(): on creation, makes one instance of every registered plugin and collects its commands intoself.commands, a dict from"plugin.method"(e.g."lamp.light") to the bound method. Find commands by introspection: look atdir(plugin)and keep attributes whoseis_commandis true.len(console)is the number of commands;"lamp.light" in consolechecks one exists.console("lamp.light", "tower-3")calls the command with the extra arguments and returns its result. An unknown path raisesKeyError(f"unknown command: {path}").console.help("lamp.light")returns the path, the signature and the first line of the docstring:"lamp.light(tower, brightness=3) - Light a tower's lantern."
command(func): a decorator that marks a method as a console command by settingfunc.is_command = True, then returnsfunc.Plugin.__init_subclass__(cls, name=None, **kwargs): registers each subclass inPlugin.registryundername, or under the lower-case class name if no name is given.Console(): on creation, makes one instance of every registered plugin and collects its commands intoself.commands, a dict from"plugin.method"(e.g."lamp.light") to the bound method. Find commands by introspection: look atdir(plugin)and keep attributes whoseis_commandis true.len(console)is the number of commands;"lamp.light" in consolechecks one exists.console("lamp.light", "tower-3")calls the command with the extra arguments and returns its result. An unknown path raisesKeyError(f"unknown command: {path}").console.help("lamp.light")returns the path, the signature and the first line of the docstring:"lamp.light(tower, brightness=3) - Light a tower's lantern."
main.py Python sleeping
Press Run to try your code, then Check to test it.