Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

19 May, 2024: Line wrapping has been changed to be more consistent with Usenet standards.
 If you find that it is broken please let me know here rocksolid.nodes.help


devel / comp.lang.python / Re: Using __new__ (Posting On Python-List Prohibited)

SubjectAuthor
* Using __new__Jonathan Gossage
`* Re: Using __new__Stefan Ram
 `- Re: Using __new__ (Posting On Python-List Prohibited)Lawrence D'Oliveiro

1
Using __new__

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

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25296&group=comp.lang.python#25296

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: jgossage@gmail.com (Jonathan Gossage)
Newsgroups: comp.lang.python
Subject: Using __new__
Date: Sat, 17 Feb 2024 17:35:21 -0500
Lines: 41
Message-ID: <mailman.70.1708209363.3227.python-list@python.org>
References: <CAApdmf1-8Mu4wK+V0Sd61v-ySZE0+pLO5OHUZOXa1aubty1LvA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de wZHC8e2cb4qzCQocdqwjsgPMHSQTRuQ4OgPGLZKiOTkw==
Cancel-Lock: sha1:AfXkBsZFyXEfqYQgxDb5fTOmdpU= sha256:N3GvYSgdiyhESFUW0Bm1oXcUKSYY24tTRT350Xu9i74=
Return-Path: <jgossage@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=I1r/kxs5;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.004
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'looks': 0.02; 'argument':
0.04; 'def': 0.04; 'traceback': 0.04; '(most': 0.05; 'last):':
0.05; 'typeerror:': 0.09; '-&gt;': 0.16; 'none:': 0.16;
'proceed?': 0.16; 'python': 0.16; '16,': 0.19; 'to:addr:python-
list': 0.20; 'skip:_ 10': 0.22; 'code': 0.23; 'suggestions': 0.28;
'takes': 0.31; '"",': 0.32; 'subject:Using': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'received:google.com': 0.34;
'following': 0.35; 'from:addr:gmail.com': 0.35; 'class': 0.37;
'file': 0.38; 'quite': 0.39; 'use': 0.39; 'method': 0.61; 'skip:o
10': 0.61; 'skip:k 10': 0.64; 'exactly': 0.68; 'skip:f 20': 0.75;
'puzzled': 0.84; 'skip:" 50': 0.84; 'skip:j 20': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1708209359; x=1708814159; darn=python.org;
h=to:subject:message-id:date:from:mime-version:from:to:cc:subject
:date:message-id:reply-to;
bh=FrN2YdIvotD/TFfcFs7+Hvw6YH2AfLfXdrx56VYMv44=;
b=I1r/kxs5MpiVvjdUumfTWSA7EWSwLx7rJkz0e4Z3eSvHObM7b8jNfyuZRcLURQZJ5I
2ZevpRtaQNjoDUpdy995ca37tNX4+SbVxVuxnxJuXibxzDxBxZnysOSdOLnS5dHBimGd
cQU430HkWOShYaitc0f8iJ04V6zUBIHpiRHizzFkENm8BogC9+PeBim+JPXvfixefl2C
cAzD/hVrDzIptBv6BKa+651mGDUOf5k1VXgdoPDNgtIyU4DaalkzyPndOz3VRqLiRlAl
HYTqSWW7HMLzBpYf0VbUAjrZkhGn+e5v0lrvdps7bkE0oVWlcPvThmBgAf8r+Yflb5Jg
s85w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1708209359; x=1708814159;
h=to:subject:message-id:date:from:mime-version:x-gm-message-state
:from:to:cc:subject:date:message-id:reply-to;
bh=FrN2YdIvotD/TFfcFs7+Hvw6YH2AfLfXdrx56VYMv44=;
b=O2+w0YeeJZQF8i6ijFpYewXdJBr2DpNGbNGFWzhYEBB7Pvi0uLZDlTQ17I8h5GpYgu
be75ioZk6bfWLgfAdjDW6+TTMVLVq3FVaTrMCvVlKZwBruWm9uDaVgTx04KySm3FNHir
ifzwwMNvLr4+wRVYlROlwirEkfw1opfPzhihytgFnk+Om+XkBFhVrFjqyuqOSV7yRFYo
Gm/8jZXpkawhXWT0mQqUE3jPYpRMWMrD8ESc0JCEV/nvTBeF2Uob7ClhItO1UfM1Th9K
CfSbs3GOemriL9u9AojnKca2Vyb8vW1n+N+pg9IN65xPkn9XpAP6rbvhn/XMTItzTpmT
PjYQ==
X-Gm-Message-State: AOJu0YxhniKVF7HCBNHK20fVAlp1hecPZmKMayU01t2X2M7Ajczuxl9b
SbF3LaQTvrDCVFP7wUFPCze3k8Al6CeeqDpRpw/ECSpI9tL7q/FvnZvU+mmGQR4K3J/dLKzMAQf
7p3b/VbQmSvg/+u6CN2FCkpEW0rIcknWmARmGcw==
X-Google-Smtp-Source: AGHT+IGGVGxIKDUoZsbe/yspVOeEVFeWu0nP3anrddw5IfQ2X3Qhv5KLH5nnVAbEzbLKPhWRL4O/Axz9XVhnsPtRoGo=
X-Received: by 2002:a17:90b:4b4e:b0:299:7f65:7cd1 with SMTP id
mi14-20020a17090b4b4e00b002997f657cd1mr362546pjb.9.1708209358260; Sat, 17 Feb
2024 14:35:58 -0800 (PST)
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
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: <CAApdmf1-8Mu4wK+V0Sd61v-ySZE0+pLO5OHUZOXa1aubty1LvA@mail.gmail.com>
 by: Jonathan Gossage - Sat, 17 Feb 2024 22:35 UTC

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, **kwargs) -> None:
our_attributes = ('h', 'x')
if kwargs is not None:
for k, v in kwargs.items():
if k in our_attributes:
setattr(self, k, v)

a = SingletonExample(h=1)

and I get the following result:

(PRV) jonathan@jfgdev:/PR$ python -m Library.Testing.test2
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/mnt/ProgrammingRenaissance/Library/Testing/test2.py", line 16, in
<module>
a = SingletonExample(h=1)
^^^^^^^^^^^^^^^^^^^^^
File "/mnt/ProgrammingRenaissance/Library/Testing/test2.py", line 6, in
__new__
cls._instance = super().__new__(cls, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object.__new__() takes exactly one argument (the type to
instantiate)

I am quite puzzled as it looks as if this code will not work if the
super-class is 'object'. Any suggestions on how to proceed?

--
Jonathan Gossage

Re: Using __new__

<new-20240217234535@ram.dialup.fu-berlin.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25297&group=comp.lang.python#25297

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Using __new__
Date: 17 Feb 2024 22:51:29 GMT
Organization: Stefan Ram
Lines: 10
Expires: 1 Feb 2025 11:59:58 GMT
Message-ID: <new-20240217234535@ram.dialup.fu-berlin.de>
References: <mailman.70.1708209363.3227.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 GGuATJeX5gW8q+MH6UMTUA9Ml+gH217C6Rnf/emeIZ/gwp
Cancel-Lock: sha1:oMSCJW5DhoZ30rv8o4zKB6FqR04= sha256:0ybWhV05ndgzcJrUTBfqryaYDXjUhZ3DJd+ItoMc7qE=
X-Copyright: (C) Copyright 2024 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 - Sat, 17 Feb 2024 22:51 UTC

Jonathan Gossage <jgossage@gmail.com> writes:
>I am attempting to use the __new__ method in the following code:
>class SingletonExample(object):

Above, you specify that the superclass is "object".

>super().__new__(cls, **kwargs)

Now, since you know the superclass to be "object",
why can't you just write "super().__new__( cls )"?

Re: Using __new__ (Posting On Python-List Prohibited)

<uqridt$lp2s$2@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25303&group=comp.lang.python#25303

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.python
Subject: Re: Using __new__ (Posting On Python-List Prohibited)
Date: Sun, 18 Feb 2024 00:19:09 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 5
Message-ID: <uqridt$lp2s$2@dont-email.me>
References: <mailman.70.1708209363.3227.python-list@python.org>
<new-20240217234535@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 18 Feb 2024 00:19:09 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ef266a3a922f269062f854d615e239ef";
logging-data="713820"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Pas4IO5oaCKngkqU7gvuE"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:2RQY0gCEqWfvEHZSczFqBwNAcfU=
 by: Lawrence D'Oliv - Sun, 18 Feb 2024 00:19 UTC

On 17 Feb 2024 22:51:29 GMT, Stefan Ram wrote:

> Above, you specify that the superclass is "object".

Which is redundant, anyway.


devel / comp.lang.python / Re: Using __new__ (Posting On Python-List Prohibited)

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor