Re: Using __new__

2024-02-17 Thread dn via Python-list
On 18/02/24 13:21, Jonathan Gossage wrote: The problem is that if you are dealing with a library class, you may have times when the superclass is 'object' while at other times, with a different inheritance hierarchy, the superclass may need arguments. My thought is that the object class __new__

Re: Using __new__

2024-02-17 Thread dn via Python-list
On 18/02/24 12:48, Jonathan Gossage wrote: The problem that I am facing is that when the superclass is not 'object', the __init__ method may well need arguments. I do not know how to determine if the superclass is 'object'. For what it is worth, any attempt to use this with different arguments 

Re: Using __new__

2024-02-17 Thread dn via Python-list
On 18/02/24 11:35, Jonathan Gossage via Python-list wrote: I am attempting to use the __new__ method in the following code: class SingletonExample(object): _instance = None def __new__(cls, **kwargs): if cls._instance is None: cls._instance = super().__new__(cls,

Re: Using __new__

2024-02-17 Thread MRAB via Python-list
On 2024-02-17 22:35, Jonathan Gossage via Python-list wrote: I am attempting to use the __new__ method in the following code: class SingletonExample(object): _instance = None def __new__(cls, **kwargs): if cls._instance is None: cls._instance = super().__new__(cl

Using __new__

2024-02-17 Thread Jonathan Gossage via Python-list
I am attempting to use the __new__ method in the following code: class SingletonExample(object): _instance = None def __new__(cls, **kwargs): if cls._instance is None: cls._instance = super().__new__(cls, **kwargs) return cls._instance def __init__(self, *