提交 3757de67 authored 作者: Frederic's avatar Frederic

Make subclass of Generic don't share the shared instance.

上级 b7c58547
...@@ -401,10 +401,15 @@ class SingletonType(Type): ...@@ -401,10 +401,15 @@ class SingletonType(Type):
It saves having to implement __eq__ and __hash__ It saves having to implement __eq__ and __hash__
""" """
__instance = None __instance = None
def __new__(cls): def __new__(cls):
if cls.__instance is None: # I don't understand why the subclass of subclass of
# SingletonType would share the __instance. So I add the check
# for the type.
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
def __str__(self): def __str__(self):
return self.__class__.__name__ return self.__class__.__name__
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论