提交 6cfb201b authored 作者: Frederic's avatar Frederic

Add explanation of why this work correctly.

上级 04b75c28
...@@ -403,9 +403,11 @@ class SingletonType(Type): ...@@ -403,9 +403,11 @@ class SingletonType(Type):
__instance = None __instance = None
def __new__(cls): def __new__(cls):
# I don't understand why the subclass of subclass of # If sub-subclass of SingletonType don't redeclare __instance
# SingletonType would share the __instance. So I add the check # when we look for it, we will find it in the subclass. We
# for the type. # don't want that, so we check the class. When we add one, we
# add one only to the current class, so all is working
# correctly.
if cls.__instance is None or not isinstance(cls.__instance, cls): if cls.__instance is None or not isinstance(cls.__instance, cls):
cls.__instance = Type.__new__(cls) cls.__instance = Type.__new__(cls)
return cls.__instance return cls.__instance
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论