This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ppt000
Recipients CuriousLearner, ncoghlan, ppt000, serhiy.storchaka, xtreak
Date 2018-11-27.10:22:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1543314136.56.0.788709270274.issue31506@psf.upfronthosting.co.za>
In-reply-to
Content
I am not sure if the following is resolved by your proposal, I post it just in case:
The following code works:
	1. class Singleton(object):
	2.     def __new__(cls, *args, **kwargs):
	3.         if not hasattr(cls, 'instance'):
	4.             cls.instance = super(Singleton, cls).__new__(cls)
	5.             cls.instance._init_pointer = cls.instance._init_properties
	6.         else:
	7.             cls.instance._init_pointer = lambda *args, **kwargs: None # do nothing
	8.         return cls.instance
	9.     def __init__(self, *args, **kwargs):
	10.         super(Singleton, self).__init__()
	11.         self._init_pointer(*args, **kwargs)
	12.     def _init_properties(self, tag):
	13.         self.info = tag
	14. #
	15. if __name__ == '__main__':
	16.     S1 = Singleton('I am S1')
	17.     print('S1 info is:' + S1.info)
	18.     S2 = Singleton('Am I S2?')
	19.     print('S2 info is:' + S2.info)
However if I change line 4 into this code (which works in Python 2 by the way):
            cls.instance = super(Singleton, cls).__new__(cls, *args, **kwargs)
I get:
	TypeError: object.__new__() takes no arguments
But if I change line 4 into this (no arguments as suggested):
            cls.instance = super(Singleton, cls).__new__()
I get:
	TypeError: object.__new__(): not enough arguments
Line 10 has the same issue when changed to:
	super(Singleton, self).__init__(*args, **kwargs)
History
Date User Action Args
2018-11-27 10:22:16ppt000setrecipients: + ppt000, ncoghlan, serhiy.storchaka, CuriousLearner, xtreak
2018-11-27 10:22:16ppt000setmessageid: <1543314136.56.0.788709270274.issue31506@psf.upfronthosting.co.za>
2018-11-27 10:22:16ppt000linkissue31506 messages
2018-11-27 10:22:16ppt000create