"""按插件 API 版本与宿主支持范围做协商。""" from __future__ import annotations SUPPORTED_MIN = 1 SUPPORTED_MAX = 2 def negotiate(plugins: dict[str, int]) -> tuple[list[str], list[str]]: compatible: list[str] = [] rejected: list[str] = [] for name, version in plugins.items(): if SUPPORTED_MIN <= version <= SUPPORTED_MAX: compatible.append(name) else: rejected.append(name) return sorted(compatible), sorted(rejected) def main() -> None: plugins = {"alpha": 1, "beta": 3, "gamma": 2, "delta": 0} compatible, rejected = negotiate(plugins) print(f"compatible: {compatible}") print(f"rejected: {rejected}") if __name__ == "__main__": main()