Am Wed, Oct 04, 2023 at 05:25:04PM +1300 schrieb dn via Python-list:
> The first question when dealing with the Singleton Pattern is what to do when
> more than
> one instantiation is attempted:
>
> - silently return the first instance
This, in my case.
> and so, returning to the matter of
On 04/10/2023 19.41, Chris Angelico via Python-list wrote:
On Wed, 4 Oct 2023 at 15:27, dn via Python-list wrote:
- should the class have been called either;
class SomethingSingleton():
or a Singleton() class defined, which is then sub-classed, ie
class Something( Singleton ):
On Wed, 4 Oct 2023 at 17:47, Greg Ewing via Python-list
wrote:
>
> On 4/10/23 5:25 pm, dn wrote:
> > The first question when dealing with the Singleton Pattern is what to do
> > when more than one instantiation is attempted
>
> My preferred way of handling singletons is not to expose the class
>
On 4/10/23 5:25 pm, dn wrote:
The first question when dealing with the Singleton Pattern is what to do
when more than one instantiation is attempted
My preferred way of handling singletons is not to expose the class
itself, but a function that creates an instance the first time it's
called,
On Wed, 4 Oct 2023 at 15:27, dn via Python-list wrote:
> - should the class have been called either;
>
> class SomethingSingleton():
>
> or a Singleton() class defined, which is then sub-classed, ie
>
> class Something( Singleton ):
>
> in order to better communicate the coder's intent
On 02/10/2023 00.57, Karsten Hilbert via Python-list wrote:
Sorry for having conflated the core of the matter with all
the Borg shenanigans, that's where I found the problem in my
real code, so there :-)
The first question when dealing with the Singleton Pattern is what to do
when more than
On Mon, 2 Oct 2023 at 09:10, Barry via Python-list
wrote:
>
>
>
> > On 1 Oct 2023, at 19:36, Richard Damon via Python-list
> > wrote:
> >
> > Perhaps a better method would be rather than just using the name and
> > catching the exception, use a real already_initialized flag (set to True
> >
> On 1 Oct 2023, at 19:36, Richard Damon via Python-list
> wrote:
>
> Perhaps a better method would be rather than just using the name and catching
> the exception, use a real already_initialized flag (set to True when you
> initialize), and look it up with getattr() with a default value
My view of the issue is that the "trick" of "evaluating" a name to see
if the object has been initialized is just a tad on the "tricky" side,
and the annotation/value is really incorrect.
The name at the point you are annotating it, isn't really a "bool"
because a bool will always have either
On Sun, 1 Oct 2023 at 22:58, Karsten Hilbert via Python-list
wrote:
>
> Sorry for having conflated the core of the matter with all
> the Borg shenanigans, that's where I found the problem in my
> real code, so there :-)
>
> Consider this:
>
> #
Sorry for having conflated the core of the matter with all
the Borg shenanigans, that's where I found the problem in my
real code, so there :-)
Consider this:
#
class Surprise:
def __init__(self, with_type_annotation=False):
On 01/10/2023 11.25, Karsten Hilbert via Python-list wrote:
Am Sun, Oct 01, 2023 at 09:04:05AM +1300 schrieb dn via Python-list:
class WorkingSingleton(Borg):
def __init__(self):
print(self.__class__.__name__, ':')
try:
Am Sun, Oct 01, 2023 at 09:04:05AM +1300 schrieb dn via Python-list:
> >class WorkingSingleton(Borg):
> >
> > def __init__(self):
> > print(self.__class__.__name__, ':')
> > try:
> > self.already_initialized
> > print('already
On 01/10/2023 08.00, Karsten Hilbert via Python-list wrote:
A type annotation isn't supposed to change what code does,
or so I thought:
#
class Borg:
_instances:dict = {}
def __new__(cls, *args, **kargs):
On 9/30/23 13:00, Karsten Hilbert via Python-list wrote:
A type annotation isn't supposed to change what code does,
or so I thought:
#
class Borg:
_instances:dict = {}
def __new__(cls, *args, **kargs):
A type annotation isn't supposed to change what code does,
or so I thought:
#
class Borg:
_instances:dict = {}
def __new__(cls, *args, **kargs):
# look up subclass instance cache
if
16 matches
Mail list logo