示例工程 30-plugin-registry-design

30-plugin-registry-design/01-decorator-registry/README.md

markdown · 0.6 KB

# 01 · decorator-registry
 
**演示**:用 `@register("name")` 装饰器把函数登记进字典;重复名直接抛错。注册在导入时完成,调用方只依赖名字。
**运行**:
 
```sh
uv run python examples/30-plugin-registry-design/01-decorator-registry/decorator_registry.py
```
 
**预期输出**(3.12.9):
 
```text
commands: ['bye', 'hello']
hello: hello Ada
duplicate: duplicate command: hello
```
 
**依赖**:仅标准库。
**注意**:装饰器注册简单直观,但要求插件模块被 import;入口点发现(03)解决「不 import 也能找插件」的问题。