Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"One lawyer can steal more than a hundred men with guns." -- The Godfather


devel / comp.lang.python / Re: type annotation vs working code

SubjectAuthor
* Re: type annotation vs working codedn
+* Re: type annotation vs working codeGreg Ewing
|`- Re: type annotation vs working codeChris Angelico
`- Re: type annotation vs working codeStefan Ram

1
Re: type annotation vs working code

<mailman.392.1696393517.23016.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=28520&group=comp.lang.python#28520

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonList@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: type annotation vs working code
Date: Wed, 4 Oct 2023 17:25:04 +1300
Organization: DWM
Lines: 149
Message-ID: <mailman.392.1696393517.23016.python-list@python.org>
References: <ZRhwWN29i3mskxEL@hermes.hilbert.loc>
<ecc36615-1844-455f-b701-2bd41d98e9e1@DancesWithMice.info>
<ZRigRwHpNReUo5rF@hermes.hilbert.loc>
<4f1c9568-3850-4847-b357-740f79b0a79b@DancesWithMice.info>
<ZRlelmUwOR/wcPqR@hermes.hilbert.loc>
<f093d0a9-67b3-4baa-baae-3666c9847a14@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de WMj+mYPS2+AI4IViLmKr5AjUoaZCOnrSHjgG7RFsGA7A==
Cancel-Lock: sha1:3EiSZx5E8cP7CQSEC8HJ8e0iwqM= sha256:L/XEg7/IfC1NtbjmAkBmcviCgVl9/mFuK2x7XeDH960=
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=JykIjG9K; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'this:': 0.03; 'def': 0.04;
'achieved': 0.07; 'pep': 0.07; 'tests': 0.07; ':-)': 0.09; '=dn':
0.09; 'borg': 0.09; 'c++.': 0.09; 'from:addr:danceswithmice.info':
0.09; 'from:addr:pythonlist': 0.09; 'instances': 0.09; 'karsten':
0.09; 'language,': 0.09; 'question:': 0.09;
'received:192.168.1.64': 0.09; '(eg': 0.16; '(unless': 0.16;
'661': 0.16; 'akin': 0.16; 'confusion': 0.16; 'dict': 0.16; 'eg:':
0.16; 'explicit': 0.16; 'generating': 0.16; 'hilbert': 0.16;
'instance': 0.16; 'intent': 0.16; 'mentions': 0.16; 'message-
id:@DancesWithMice.info': 0.16; 'none:': 0.16; 'preceded': 0.16;
'received:cloud': 0.16; 'received:rangi.cloud': 0.16;
'subject:code': 0.16; 'subject:working': 0.16; 'value?': 0.16;
'wrote:': 0.16; 'problem': 0.16; 'python': 0.16; 'values': 0.17;
'to:addr:python-list': 0.20; 'communicate': 0.22; 'exception':
0.22; 'skip:_ 10': 0.22; 'version': 0.23; 'code': 0.23;
'extension': 0.25; 'seems': 0.26; 'justify': 0.26; 'pattern':
0.26; "wasn't": 0.26; "isn't": 0.27; '>>>': 0.28; 'header:User-
Agent:1': 0.30; 'present': 0.30; 'attempt': 0.31; 'code,': 0.31;
'module': 0.31; 'raise': 0.31; 'header:Organization:1': 0.31;
'wondering': 0.31; 'think': 0.32; "doesn't": 0.32; 'question':
0.32; 'language.': 0.32; 'python-list': 0.32; 'returning': 0.32;
'said,': 0.32; 'received:192.168.1': 0.32; 'but': 0.32; 'there':
0.33; 'same': 0.34; 'core': 0.34; 'mean': 0.34; 'header:In-Reply-
To:1': 0.34; 'url:)': 0.35; "we're": 0.35; 'also,': 0.36;
'functions': 0.36; "skip:' 10": 0.37; 'using': 0.37; 'class':
0.37; 'others': 0.37; 'received:192.168': 0.37; 'quite': 0.39;
'added': 0.39; 'this,': 0.39; 'list': 0.39; 'use': 0.39;
'something': 0.40; 'should': 0.40; 'sorry': 0.60; "there's": 0.61;
'limited': 0.62; 'true': 0.63; 'between': 0.63; 'leading': 0.63;
'full': 0.64; 'number,': 0.64; 'speaking': 0.64; 'smart': 0.67;
'matter': 0.68; 'further': 0.69; 'order': 0.69; 'interpreted':
0.69; 'sequence': 0.69; 'skip:w 20': 0.69; "you'll": 0.73;
'article': 0.73; 'supposed': 0.76; 'tracking': 0.76; '(that':
0.84; 'attribute': 0.84; 'comprehend': 0.84; 'conflated': 0.84;
'implies': 0.84; 'interpreting': 0.84; '...and': 0.91;
'discusses': 0.91; 'subject:type': 0.91; 'assess': 0.93;
'implied': 0.93
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud DA8215119
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1696393510;
bh=SFBvwvXaNuSvKZsGcKj3/dQslVgRGzyZFoLdN3o3X4I=;
h=Date:Subject:To:References:From:In-Reply-To:From;
b=JykIjG9KV0vmPTTXSOdbM3qDbWtVPRoFzGFo4UJewdHu2TDR4CW5spOh8HYG7ALHF
D+/CCnK5ukBUAVX9hjBggjKAhP6rOLG2I3TyevATz47WR7zOdkJ5BSaxWjC6EgX7ks
Hl9IXIVoQUDlKR0gcIW5hPumLWc8B6OlailouQL7loEBTiiaEwKTkKE8gJbwS6J/R3
pqi52kCYA7AsrqCXcTL+5gMmsONDQZ2/FGFFotDhPaTWLlyxMszID/8bno7Yg+x24t
38cV6ixgHZaZcZcA7I1aAKv/BknSc+pOOdyRvIJxFOHhMRfmhgQwYwEDMIX8lI+ybs
P45xJlqf5bUig==
User-Agent: Mozilla Thunderbird
Content-Language: en-GB
In-Reply-To: <ZRlelmUwOR/wcPqR@hermes.hilbert.loc>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <f093d0a9-67b3-4baa-baae-3666c9847a14@DancesWithMice.info>
X-Mailman-Original-References: <ZRhwWN29i3mskxEL@hermes.hilbert.loc>
<ecc36615-1844-455f-b701-2bd41d98e9e1@DancesWithMice.info>
<ZRigRwHpNReUo5rF@hermes.hilbert.loc>
<4f1c9568-3850-4847-b357-740f79b0a79b@DancesWithMice.info>
<ZRlelmUwOR/wcPqR@hermes.hilbert.loc>
 by: dn - Wed, 4 Oct 2023 04:25 UTC

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 one instantiation is attempted:

- silently return the first instance
- raise an exception

The 'problem' interpreting the original code was that the 'Borg
Pattern', is not limited in number, but is where some class-attribute
list (or dict) is used to enable all instances to be aware of each of
the others (IIRC).

Is choosing names as important as selecting/implementing smart algorithms?

> Consider this:
>
> #----------------------------------------------------
> class Surprise:
> def __init__(self, with_type_annotation=False):
> if with_type_annotation:
> try:
> self.does_not_exist:bool
> print('does_not_exist does exist')
> except AttributeError:
> print('does_not_exist does not exist')
> return
>
> try:
> self.does_not_exist
> print('does_not_exist does exist')
> except AttributeError:
> print('does_not_exist does not exist')
>
> Surprise(with_type_annotation = False)
> Surprise(with_type_annotation = True)
> #----------------------------------------------------
>
> Is this how it is supposed to be ?

Wasn't this answered earlier? (@Mats)

That self.does_not_exist:bool isn't interpreted by Python to mean the
same as self.does_not_exist.

>> ...and so we're addressing the important question: the try-test is for existence, cf for
>> some value.
>>
>> This can also be achieved by using the attribute in a legal expression, eg:
> ...
>> Might this remove the confusion (ref: @Mats):
>>
>> self.already_initialized:bool == True
>
> Not for me as that would _create_ already_initialized on the
> instance. It would not allow me to test for it.
>
>>> Which seems akin constructs for generating compatibility
>>> between versions.
>>
>> versions of ?
>
> Of the language. Sometimes one tests for existence of a given
> class in a module and defines said class oneself if it does
> not exist. But that's leading astray.
>
>> What is the intent: a class where each instance is aware of every other instance - yet
>> the word "Singleton" implies there's only one (cf a dict full of ...)?
>
> The latter.

and so, returning to the matter of 'readability':

- the name "Borg" de-railed comprehension

- _instances:dict = {} implied the tracking of more than one

- 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 to the reader?

- from there, plenty of 'templates' exist for Singletons, so why do
something quite different/alien to the reader?
(thus concurring with @Richard: "tricky" subverts 'readability')

- is it better to use a technique which 'we' will recognise, or to ask
'us' to comprehend something 'new'?
(unless the 'new' is taking-advantage of a recent extension to the
language, eg switch; to justify 'trail-blazing' a
new/improved/replacement 'best practice')

- part of the 'tricky' seems to be an attempt to assess using an
instance-attribute, rather than a class-attribute. If the :bool (or
whichever) typing-annotation is added to a class-attribute (eg
_instance), will the problem arise?

- does the sequence

_instance = False
...
if not cls._instance:
ie the explicit version
if cls._instance == False:

measure 'existence' or a value?

- does the sequence

_instance = None
...
if not cls._instance:
ie the explicit version:
if cls._instance is None:

measure 'existence' or identity?
(indeed, are they more-or-less the same concept?)

- do the *attr() functions test for 'existence'?

(that said, most of the code-examples I spotted, in reading-up on this,
use either None or False - et tu Brute!)

Speaking of reading-up:

- am wondering where PEP 661 - Sentinel Values is 'going'?

- this article (https://python-patterns.guide/gang-of-four/singleton/)
mentions that the original GoF Singleton Pattern preceded Python
(particularly Python 3 classes). Also, that Python doesn't have
complications present in C++. It further discusses "several drawbacks",
which also champion 'readability' over 'trick' or 'sophistication'. I
think you'll enjoy it!

--
Regards,
=dn

Re: type annotation vs working code

<ko4fu3Fsk1mU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=28522&group=comp.lang.python#28522

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: greg.ewing@canterbury.ac.nz (Greg Ewing)
Newsgroups: comp.lang.python
Subject: Re: type annotation vs working code
Date: Wed, 4 Oct 2023 19:44:19 +1300
Lines: 12
Message-ID: <ko4fu3Fsk1mU1@mid.individual.net>
References: <ZRhwWN29i3mskxEL@hermes.hilbert.loc>
<ecc36615-1844-455f-b701-2bd41d98e9e1@DancesWithMice.info>
<ZRigRwHpNReUo5rF@hermes.hilbert.loc>
<4f1c9568-3850-4847-b357-740f79b0a79b@DancesWithMice.info>
<ZRlelmUwOR/wcPqR@hermes.hilbert.loc>
<f093d0a9-67b3-4baa-baae-3666c9847a14@DancesWithMice.info>
<mailman.392.1696393517.23016.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net X2OrrBCQ/kGoi+rjfC9y3wzGdtCMWW6V6P5r2k2ylPDL7uwBLf
Cancel-Lock: sha1:O8MVCQB/JmPjrfIotnEX3pNDXGo= sha256:YqMDHzxKvv1dvfkmqJ6oVAgJ9X/I9Ua/+Gr2qbVK3hE=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Content-Language: en-US
In-Reply-To: <mailman.392.1696393517.23016.python-list@python.org>
 by: Greg Ewing - Wed, 4 Oct 2023 06:44 UTC

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, and returns that instance subsequently. The problem then
doesn't arise.

--
Greg

Re: type annotation vs working code

<mailman.394.1696402199.23016.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=28523&group=comp.lang.python#28523

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: type annotation vs working code
Date: Wed, 4 Oct 2023 17:49:44 +1100
Lines: 22
Message-ID: <mailman.394.1696402199.23016.python-list@python.org>
References: <ZRhwWN29i3mskxEL@hermes.hilbert.loc>
<ecc36615-1844-455f-b701-2bd41d98e9e1@DancesWithMice.info>
<ZRigRwHpNReUo5rF@hermes.hilbert.loc>
<4f1c9568-3850-4847-b357-740f79b0a79b@DancesWithMice.info>
<ZRlelmUwOR/wcPqR@hermes.hilbert.loc>
<f093d0a9-67b3-4baa-baae-3666c9847a14@DancesWithMice.info>
<mailman.392.1696393517.23016.python-list@python.org>
<ko4fu3Fsk1mU1@mid.individual.net>
<CAPTjJmqKA60Q0gmKd4pkO_LJPCxxqb4UpkFaWS+vEkD=8fBX0A@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de L9waxM9OwZTMxzGPQ70AeAvqhyR/jL1ieDdcXf5doQ4Q==
Cancel-Lock: sha1:WI+lLrNYYkxL1j0b+skjEI/HVb0= sha256:xxLFghhW3FApL2H4Wm3K+Uu2TFE9k6BWD22yE8IsohM=
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=B0nPzWhm;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '2023': 0.07; 'itself,':
0.09; 'much,': 0.09; 'chrisa': 0.16; 'expose': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'greg': 0.16; 'instance': 0.16; 'option.': 0.16; 'personally,':
0.16; 'subject:code': 0.16; 'subject:working': 0.16; 'wrote:':
0.16; 'problem': 0.16; 'pm,': 0.19; 'to:addr:python-list': 0.20;
'creates': 0.22; 'returns': 0.22; 'do,': 0.26; 'pattern': 0.26;
'function': 0.27; "doesn't": 0.32; 'question': 0.32; 'python-
list': 0.32; 'message-id:@mail.gmail.com': 0.32; 'but': 0.32;
'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'handling': 0.35; 'from:addr:gmail.com': 0.35; "it's": 0.37;
'class': 0.37; 'way': 0.38; 'use': 0.39; 'wed,': 0.39; 'spam':
0.65; 'subject:type': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1696402196; x=1697006996; darn=python.org;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=7TBRECsfsNrpfy7YdjARCprUrAwc5c+kVGTgilbWiE8=;
b=B0nPzWhm8je6DnomfbW8mwHtMSe3Y0IKibm4tnjH1vrqYzHFlAxRmOsmLhKUsvC6oJ
adR4kIHJdkSc8P2CjgHkMRhw54/7X3xok2HkxLOpBffGpNr/xACY1oUvQc8w3ZgR4BmU
VfBGCuio/vpRDcgDSWLJQrMsUsJlCbi6I2P0BsAkmiBgvndBxVOcTmB+3ZFS1QYoKqnk
4Xp8uMt7hZyij+1X19n76hnDtN+g5nL5g+g4BjM1V3nBQ0unpzoeohFtlR7d61fIAG46
3odhlcH+xDlscthVlmq1CnTITgezHEehJ/bbVOXhHMDHJQbylR99GofIX1QkWF+vNoVl
9CRw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1696402196; x=1697006996;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=7TBRECsfsNrpfy7YdjARCprUrAwc5c+kVGTgilbWiE8=;
b=Og3BMNK45ZkOdYxRE55rOSi1vv9X5O724yLJ5PgILdKFVhpithtpMbt9VPgdWxvreI
w77T5ChZS97vbvabY3CBZXfbpjAEr2LLd0ZBi+iaJDp6hbxca+bSnlguboyh7Ct5kSkQ
HZbP8/nrf6x0BRt8LbxY+31prQ52HuN4ngUFgy9ab2V8oIS6PRC8jsDghbhWO6wWNQ4v
i8+Y9S84XTmfUbSNyjvmgsUaT132C5JKJE+fV2O/1PtcVigWjiKE1m2/PoQc/RoyLDIj
2KqQpPkeCA50zPp6i2hOOpDvADWhjemAGl5u3MjSbj51S3yQIyLgHKSYE1XzudUd80w9
yh7w==
X-Gm-Message-State: AOJu0YyPZAiSvBEqqRcjhqnPBLdDdC0H0iMVA2CT/NZaDrnPL1XztCyL
ub0B+Imc8vEaZMVseOwACXgQr5m60rnB8y1f7ZXHC5tJ
X-Google-Smtp-Source: AGHT+IFmxOhqLorSDG8F8WU2XyBppFyS8n9ID4D/+LcC2DAczzzznzW0mWM9Z783F3dcr4gJmdAW9rtCnHSCcG5tH50=
X-Received: by 2002:ac2:58f1:0:b0:500:ac0b:8d52 with SMTP id
v17-20020ac258f1000000b00500ac0b8d52mr1134022lfo.7.1696402196427; Tue, 03 Oct
2023 23:49:56 -0700 (PDT)
In-Reply-To: <ko4fu3Fsk1mU1@mid.individual.net>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmqKA60Q0gmKd4pkO_LJPCxxqb4UpkFaWS+vEkD=8fBX0A@mail.gmail.com>
X-Mailman-Original-References: <ZRhwWN29i3mskxEL@hermes.hilbert.loc>
<ecc36615-1844-455f-b701-2bd41d98e9e1@DancesWithMice.info>
<ZRigRwHpNReUo5rF@hermes.hilbert.loc>
<4f1c9568-3850-4847-b357-740f79b0a79b@DancesWithMice.info>
<ZRlelmUwOR/wcPqR@hermes.hilbert.loc>
<f093d0a9-67b3-4baa-baae-3666c9847a14@DancesWithMice.info>
<mailman.392.1696393517.23016.python-list@python.org>
<ko4fu3Fsk1mU1@mid.individual.net>
 by: Chris Angelico - Wed, 4 Oct 2023 06:49 UTC

On Wed, 4 Oct 2023 at 17:47, Greg Ewing via Python-list
<python-list@python.org> 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
> itself, but a function that creates an instance the first time it's
> called, and returns that instance subsequently. The problem then
> doesn't arise.
>

That's one option. Personally, I don't use them very much, but if I
do, it's usually actually as a class that never gets instantiated:

class PileOfAttributes:
x = 1
y = 2
spam = "ham"

ChrisA

Re: type annotation vs working code

<singletons-20231004125510@ram.dialup.fu-berlin.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=28525&group=comp.lang.python#28525

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: type annotation vs working code
Date: 4 Oct 2023 11:56:50 GMT
Organization: Stefan Ram
Lines: 21
Expires: 1 Sep 2024 11:59:58 GMT
Message-ID: <singletons-20231004125510@ram.dialup.fu-berlin.de>
References: <ZRhwWN29i3mskxEL@hermes.hilbert.loc> <ecc36615-1844-455f-b701-2bd41d98e9e1@DancesWithMice.info> <ZRigRwHpNReUo5rF@hermes.hilbert.loc> <4f1c9568-3850-4847-b357-740f79b0a79b@DancesWithMice.info> <ZRlelmUwOR/wcPqR@hermes.hilbert.loc> <f093d0a9-67b3-4baa-baae-3666c9847a14@DancesWithMice.info> <mailman.392.1696393517.23016.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de F3LStlc+JAHPoPP3Ho+j1AIclbq9aiRAMxUcZ5ypAOBjG4
Cancel-Lock: sha1:zMQaVfLahS4B9dVe4azeSXRFc7c= sha256:4L6LAkKZhUHPnWVtws8Wtj3N8Pz0rTFYUnKvWYPew0k=
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE-1901, en-US, it, fr-FR
 by: Stefan Ram - Wed, 4 Oct 2023 11:56 UTC

dn <PythonList@DancesWithMice.info> writes:
>- should the class have been called either;
> class SomethingSingleton():
>or a Singleton() class defined, which is then sub-classed, ie

A singleton is a single instance of a class that usually is
used "globally" in an application. Such as "root" in

import logging

root = logging.getLogger()

. So, when a singleton is needed in Python, I would follow
the model of "getLogger". You do not have to put in effort
to keep any client from creating more than one instance of
a class. Multiple instances of a class intended for singletons
might help when one is writing tests for this class.

(My above opinion was stolen from Brandon Rhodes.)


devel / comp.lang.python / Re: type annotation vs working code

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor