From e6751285660863cda41f1ca7dc147238916425bc Mon Sep 17 00:00:00 2001 From: Skip Montanaro Date: Thu, 8 Apr 2004 21:14:34 +0000 Subject: [PATCH] Add Ping's enhanced singleton decorator. --- pep-0318.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pep-0318.txt b/pep-0318.txt index c51e39d06..070d16ec7 100644 --- a/pep-0318.txt +++ b/pep-0318.txt @@ -270,7 +270,12 @@ some examples of use. :: def singleton(cls): - return cls() + instances = {} + def getinstance(): + if cls not in instances: + instances[cls] = cls() + return instances[cls] + return getinstance class MyClass [singleton]: ...