type annotation vs working code
Chris Angelico
rosuav at gmail.com
Wed Oct 4 02:49:44 EDT 2023
On Wed, 4 Oct 2023 at 17:47, Greg Ewing via Python-list
<python-list at 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
More information about the Python-list
mailing list