【发布时间】:2026-02-13 23:25:03
【问题描述】:
我有一个类似的界面:
class IRepository(Interface):
def __init__(path, **options):
pass
我为 Git 和 Mercurial 实现了这个接口。现在我想编写存储库工厂,它接受一个字符串(路径)并返回一个 IRepository,通过探测它是 git 还是 hg 存储库。
但是,简单地说:
registerAdapter(repofactory, (str, unicode, ), IRepository)
不起作用,因为str 和unicode 都不支持IInterface 接口。
现在,我要:
registerAdapter(repofactory, (Interface, ), IRepository)
但我想知道是否有接口只匹配字符串对象和其他 Python 内置类型。
【问题讨论】:
标签: adapter zope zope.interface