Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Marriage is low down, but you spend the rest of your life paying for it." -- Baskins


devel / comp.lang.python / Re: How to replace an instance method?

SubjectAuthor
* Re: How to replace an instance method?Eryk Sun
`* Re: How to replace an instance method?Stefan Ram
 `* Re: How to replace an instance method?Stefan Ram
  +- Re: How to replace an instance method?Eryk Sun
  +- Re: How to replace an instance method?2QdxY4RzWzUUiLuE
  `- Re: How to replace an instance method?Eryk Sun

1
Re: How to replace an instance method?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: eryk...@gmail.com (Eryk Sun)
Newsgroups: comp.lang.python
Subject: Re: How to replace an instance method?
Date: Sat, 17 Sep 2022 20:37:58 -0500
Lines: 14
Message-ID: <mailman.460.1663465082.20444.python-list@python.org>
References: <f9f8bac0-9a27-8615-6164-38aa2d9e0fbb@t-online.de>
<CACL+1avBfoS0xDPE1F1CuJDSzDzi_6Ra8FT04c_-Ro1+Uk3OeQ@mail.gmail.com>
<a8db9987-7f35-6b45-1ce9-f17a880dc00a@t-online.de>
<CAPTjJmoPhVkGRqLzCUFDntp2JpR5VX_1qTYJJtj8AnAtDOAWnA@mail.gmail.com>
<CACL+1atihVKMbap8CKEoYuxCsmDnoOAK9N8KY-cn+G5ty2EUHw@mail.gmail.com>
<CAPTjJmrcGWYVr=w9ZMVxxmrU7JT7===5Pe1C2KL5igDK7G8iGw@mail.gmail.com>
<CACL+1atiG4iE4rdDqGMy9rsq=hQV=k0fk+SrcZ0++UmFa2YeCw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de 6c0LXDxvAEXhzGq+BECfjgduPO3MDLBek0b9mLvmH10A==
Return-Path: <eryksun@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=mZS3Mg5o;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.023
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'argument': 0.04; 'class,':
0.05; 'class.': 0.07; 'angelico': 0.09; 'cc:addr:python-list':
0.09; 'other.': 0.09; 'cc:no real name:2**0': 0.14; 'accessed':
0.16; 'instance': 0.16; 'wrote:': 0.16; 'cc:addr:python.org':
0.20; 'subject:How': 0.23; 'past': 0.25; 'cc:2**0': 0.25;
'object': 0.26; 'function': 0.27; 'chris': 0.28; 'message-
id:@mail.gmail.com': 0.32; 'but': 0.32; 'same': 0.34; 'header:In-
Reply-To:1': 0.34; 'received:google.com': 0.34; 'one.': 0.35;
'from:addr:gmail.com': 0.35; "it's": 0.37; 'received:209.85':
0.37; 'class': 0.37; 'received:209': 0.39; 'received:209.85.222':
0.39; 'still': 0.40; 'in,': 0.60; 'method': 0.61; 'exactly': 0.68;
'subject:method': 0.69; 'attribute': 0.84; 'bind': 0.84; 'merely':
0.84; 'locked': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=cc:to:subject:message-id:date:from:references:in-reply-to
:mime-version:from:to:cc:subject:date;
bh=WsH+RbcE7gyHKGoiM9NOolDWZq/15DKP6MAXkmtdYiI=;
b=mZS3Mg5oIMYl10+o8ZF0V9UD1fnwVdtvmKI6lzoI2ep1jYcKkJCGZEHPEKFBkkDhnv
YzNwyHtC8IsnoJ4JVIlI6YjcwdIlpq2auZO9U9jgRUGHKXxlNqJjES0aLqeRnLYHIXHk
OgNEVerlXs+WU25TGXbsh/XWNWA6Yc6+rnTuGRsBcqtikhD9n5aQCtaNZz8Y2d3UbTrV
20erPa7h0IDDq3EGMbVQugy2pWCwp5bDpIHH9yVVh2CgAsGtiFTfF69HDwwdzMwZsYLR
rwA6Z/LWE2WiBmDK2bvL87r9D1O7n64WFz9r/VzBhbP2dX0dgVfdV6a85nuotkk6iwFC
DRWw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=cc:to:subject:message-id:date:from:references:in-reply-to
:mime-version:x-gm-message-state:from:to:cc:subject:date;
bh=WsH+RbcE7gyHKGoiM9NOolDWZq/15DKP6MAXkmtdYiI=;
b=GSaVK80vfPjB4nBoUuzsXLmis2Xzm1P9BGBfWEfN25H5gHm8cZ4JXPT0jfQ//HZAAA
KRnDEhLcMDRLwxxU/Db4jkAu9d7ivs136HNHKDFVuKan24jG59Go0wOmhiC//wbtIZJ4
UQENLAqF39xdqxQCkupmCUZHDxg9tvrxq+/afdEyFigRF5T2E1SeFvkr0d1lEtGDhlvn
mVI65Hz/F3rRUOkHlUi06NxS0tJXOiNK5zFCIpOVTMyTHefIfJA39LVkbEaUAZ3/O+LS
IFk4hLweHvqKG496B6bzG5kmBlhSVlmQmJaPqcC4TtpnrMbeSt/9ELVa4MjAo6dEJPCW
gwdQ==
X-Gm-Message-State: ACrzQf1bneyqL4rlmbBxukPlB692sTO1bT0JUBd2PFH9BebT//zDAaUT
CZiI4/Zwp1+E11kYr4hujpx+RPq+U6iAhhqr7iA=
X-Google-Smtp-Source: AMsMyM4+LW7BabXiH8zYWCgbmk9ajaUUB1ET6SUjzkOjuFAsOGov/lX7DimwuoyBvelRGgK+Mr7PAkA5/nhrILOURDg=
X-Received: by 2002:a05:620a:4416:b0:6ce:9d3c:2c35 with SMTP id
v22-20020a05620a441600b006ce9d3c2c35mr9156584qkp.78.1663465079501; Sat, 17
Sep 2022 18:37:59 -0700 (PDT)
In-Reply-To: <CAPTjJmrcGWYVr=w9ZMVxxmrU7JT7===5Pe1C2KL5igDK7G8iGw@mail.gmail.com>
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: <CACL+1atiG4iE4rdDqGMy9rsq=hQV=k0fk+SrcZ0++UmFa2YeCw@mail.gmail.com>
X-Mailman-Original-References: <f9f8bac0-9a27-8615-6164-38aa2d9e0fbb@t-online.de>
<CACL+1avBfoS0xDPE1F1CuJDSzDzi_6Ra8FT04c_-Ro1+Uk3OeQ@mail.gmail.com>
<a8db9987-7f35-6b45-1ce9-f17a880dc00a@t-online.de>
<CAPTjJmoPhVkGRqLzCUFDntp2JpR5VX_1qTYJJtj8AnAtDOAWnA@mail.gmail.com>
<CACL+1atihVKMbap8CKEoYuxCsmDnoOAK9N8KY-cn+G5ty2EUHw@mail.gmail.com>
<CAPTjJmrcGWYVr=w9ZMVxxmrU7JT7===5Pe1C2KL5igDK7G8iGw@mail.gmail.com>
 by: Eryk Sun - Sun, 18 Sep 2022 01:37 UTC

On 9/17/22, Chris Angelico <rosuav@gmail.com> wrote:
>
> A method IS a function. A bound method is a function with one argument
> locked in, but still a function.

We were talking past each other. A method object is not a function
object. You're talking about a function defined in a class that's
accessed as a method of an instance of the class. In the class, that's
just a function object; it's exactly a function, not merely
fundamentally the same thing as one. It's only when accessed as an
attribute of an instance of the type that the function's descriptor
__get__() method is called to bind it and the instance to a method
object that sets the instance as its __self__ and the function as its
__func__.

Re: How to replace an instance method?

<MethodType-20220918095521@ram.dialup.fu-berlin.de>

  copy mid

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

  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: How to replace an instance method?
Date: 18 Sep 2022 09:04:06 GMT
Organization: Stefan Ram
Lines: 78
Expires: 1 Sep 2023 11:59:58 GMT
Message-ID: <MethodType-20220918095521@ram.dialup.fu-berlin.de>
References: <f9f8bac0-9a27-8615-6164-38aa2d9e0fbb@t-online.de> <CACL+1avBfoS0xDPE1F1CuJDSzDzi_6Ra8FT04c_-Ro1+Uk3OeQ@mail.gmail.com> <a8db9987-7f35-6b45-1ce9-f17a880dc00a@t-online.de> <CAPTjJmoPhVkGRqLzCUFDntp2JpR5VX_1qTYJJtj8AnAtDOAWnA@mail.gmail.com> <CACL+1atihVKMbap8CKEoYuxCsmDnoOAK9N8KY-cn+G5ty2EUHw@mail.gmail.com> <CAPTjJmrcGWYVr=w9ZMVxxmrU7JT7===5Pe1C2KL5igDK7G8iGw@mail.gmail.com> <CACL+1atiG4iE4rdDqGMy9rsq=hQV=k0fk+SrcZ0++UmFa2YeCw@mail.gmail.com> <mailman.460.1663465082.20444.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 /0swNaPWo4nJGoDhYbHDJwFy1FtQDEebOR+92BhxQQ/ueQ
X-Copyright: (C) Copyright 2022 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, en-US, it, fr-FR
 by: Stefan Ram - Sun, 18 Sep 2022 09:04 UTC

Eryk Sun <eryksun@gmail.com> writes:
>We were talking past each other. A method object is not a function
>object.

The following code investigates whether the results of
the various substitutions actually have the method type.

main.py

import types
import functools

class example_class():
def method_original( self ): pass
def method_methodtype( self ): pass
def method_partial( self ): pass
def method_get( self ): pass

instance = example_class()

def new_method( self, param ): pass

instance.method_methodtype =\
types.MethodType( new_method, instance )

instance.method_partial =\
functools.partial(new_method, instance )

instance.method_get =\
new_method.__get__( instance )

print\
( "method_original ",
isinstance( instance.method_original, types.MethodType ))

print\
( "method_methodtype ",
isinstance( instance.method_methodtype, types.MethodType ))

print\
( "method_partial ",
isinstance( instance.method_partial, types.MethodType ))

print\
( "method_get ",
isinstance( instance.method_get, types.MethodType ))

print()

print\
( "method_original ",
type( instance.method_original ))

print\
( "method_methodtype ",
type( instance.method_methodtype ))

print\
( "method_partial ",
type( instance.method_partial ))

print\
( "method_get ",
type( instance.method_get ))

output

method_original True
method_methodtype True
method_partial False
method_get True

method_original <class 'method'>
method_methodtype <class 'method'>
method_partial <class 'functools.partial'>
method_get <class 'method'>

Re: How to replace an instance method?

<readability-20220918101045@ram.dialup.fu-berlin.de>

  copy mid

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

  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: How to replace an instance method?
Date: 18 Sep 2022 09:11:28 GMT
Organization: Stefan Ram
Lines: 10
Expires: 1 Sep 2023 11:59:58 GMT
Message-ID: <readability-20220918101045@ram.dialup.fu-berlin.de>
References: <f9f8bac0-9a27-8615-6164-38aa2d9e0fbb@t-online.de> <CACL+1avBfoS0xDPE1F1CuJDSzDzi_6Ra8FT04c_-Ro1+Uk3OeQ@mail.gmail.com> <a8db9987-7f35-6b45-1ce9-f17a880dc00a@t-online.de> <CAPTjJmoPhVkGRqLzCUFDntp2JpR5VX_1qTYJJtj8AnAtDOAWnA@mail.gmail.com> <CACL+1atihVKMbap8CKEoYuxCsmDnoOAK9N8KY-cn+G5ty2EUHw@mail.gmail.com> <CAPTjJmrcGWYVr=w9ZMVxxmrU7JT7===5Pe1C2KL5igDK7G8iGw@mail.gmail.com> <CACL+1atiG4iE4rdDqGMy9rsq=hQV=k0fk+SrcZ0++UmFa2YeCw@mail.gmail.com> <mailman.460.1663465082.20444.python-list@python.org> <MethodType-20220918095521@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de alTEGqLbyQv20a1RwuZY2w04qV1Au09gIF8AHaBtqINbqy
X-Copyright: (C) Copyright 2022 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, en-US, it, fr-FR
 by: Stefan Ram - Sun, 18 Sep 2022 09:11 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes (abbreviated):
>types.MethodType( function, instance )
>functools.partial( function, instance )
>new_method.__get__( instance )

I wonder which of these three possibilities expresses
the idea of creating a new method from a function and
an instance most clearly.

Re: How to replace an instance method?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!fu-berlin.de!uni-berlin.de!not-for-mail
From: eryk...@gmail.com (Eryk Sun)
Newsgroups: comp.lang.python
Subject: Re: How to replace an instance method?
Date: Mon, 19 Sep 2022 14:23:49 -0500
Lines: 25
Message-ID: <mailman.470.1663615432.20444.python-list@python.org>
References: <f9f8bac0-9a27-8615-6164-38aa2d9e0fbb@t-online.de>
<CACL+1avBfoS0xDPE1F1CuJDSzDzi_6Ra8FT04c_-Ro1+Uk3OeQ@mail.gmail.com>
<a8db9987-7f35-6b45-1ce9-f17a880dc00a@t-online.de>
<CAPTjJmoPhVkGRqLzCUFDntp2JpR5VX_1qTYJJtj8AnAtDOAWnA@mail.gmail.com>
<CACL+1atihVKMbap8CKEoYuxCsmDnoOAK9N8KY-cn+G5ty2EUHw@mail.gmail.com>
<CAPTjJmrcGWYVr=w9ZMVxxmrU7JT7===5Pe1C2KL5igDK7G8iGw@mail.gmail.com>
<CACL+1atiG4iE4rdDqGMy9rsq=hQV=k0fk+SrcZ0++UmFa2YeCw@mail.gmail.com>
<mailman.460.1663465082.20444.python-list@python.org>
<MethodType-20220918095521@ram.dialup.fu-berlin.de>
<readability-20220918101045@ram.dialup.fu-berlin.de>
<CACL+1avRkrLGaoMPxAh15bJqdqZO+VvvTqFSaOw-Cknp=qpsAw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de ABh4E4y0ZovyhuNrAniMfwPzBDzovxcUR2ieHm2uE+uA==
Return-Path: <eryksun@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=VG/e/tKq;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.027
X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'ram': 0.07; 'cc:addr
:python-list': 0.09; 'received:209.85.219': 0.09; 'unlike': 0.09;
'cc:no real name:2**0': 0.14; 'attributes,': 0.16; 'expose': 0.16;
'inspection': 0.16; 'instance': 0.16; 'instance)': 0.16; 'skip:>
10': 0.16; 'skip:> 20': 0.16; 'to:addr:ram': 0.16; 'to:addr:zedat
.fu-berlin.de': 0.16; 'to:name:stefan ram': 0.16; 'writes': 0.16;
'wrote:': 0.16; 'cc:addr:python.org': 0.20; 'skip:_ 10': 0.22;
'subject:How': 0.23; 'idea': 0.24; 'cc:2**0': 0.25; 'stefan':
0.26; 'creating': 0.27; "isn't": 0.27; 'function': 0.27;
"doesn't": 0.32; 'language.': 0.32; 'said,': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35; 'using':
0.37; 'received:209.85': 0.37; 'received:209': 0.39; 'method':
0.61; 'skip:i 20': 0.62; 'clear': 0.64; 'skip:t 20': 0.66; 'and,':
0.69; 'manually': 0.69; 'subject:method': 0.69; 'terms': 0.70;
'casual': 0.84; 'concept,': 0.84; 'expresses': 0.84; 'matters,':
0.84; 'method,': 0.84; 'type,': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=cc:to:subject:message-id:date:from:references:in-reply-to
:mime-version:from:to:cc:subject:date;
bh=nCK7ftlGn2xOBDCwq/B+veMijd8ayGkzWmW4pqUE+yQ=;
b=VG/e/tKqY56qdGnC+vwMasFTMqudNkxeAVCnEE7Ee5g25EHOdmh4JbsP/GCYfE6DNG
hkomplFfA37db2g6zLJd79yTCvaZYqGdpteP4JuvS8LQd2YLFAyJ7QyrYZBEqzVJx/1u
mZC0iSWN1snhk0oQ50aecptGIX4M5I2YIqC5Lb6llaQeFGaEu7h3oe2saXMUJwaTdea0
otIS2+1w7ninojtCjcqERIac8Tj7iMDrmyL+/aernvnXWbcwkJf5tSD9DNvqVCzwQdkW
kuf1qHJYO0cLNqLQrdET106rNmsKrYLruR0dpHzjbqvq8QtsBbT9h2ioxd6WSWsfo2Bf
78ug==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=cc:to:subject:message-id:date:from:references:in-reply-to
:mime-version:x-gm-message-state:from:to:cc:subject:date;
bh=nCK7ftlGn2xOBDCwq/B+veMijd8ayGkzWmW4pqUE+yQ=;
b=V2Ayp1KUARY/GuBNMx25lz9zkHKTc7F5l8FmvgI4GZP0DjIeNKk4rQILNlegpkzwyE
ceerLmqxDpXJLeye9EqpsROfdsOTjYIvNzB7jICjEooS9njrGzi84JQQhthuwAS2+lFa
NYaFrr5HZ5MXUU7k6aOEyM4dOLd2W8NoCQrEszsEaMdoPuVNsh9Znh8YC5A/8ySNpLIw
E0anrlbP3BUfziIFTpKyamrjGTt/+4gzgp5kj/D2qS1jGNSUset5IR6Mxus0KzQPkXF2
VMkwqUoaWxx6R8nidQ5yKQYWh6voga1dKWaKbxD+AijV9fTIAktWmkG6vdfH9oycAyj8
wHAQ==
X-Gm-Message-State: ACrzQf0XW+ZIeLPu+r/pdsFVs94FbuhRlUIgrMV592+IVOAkji2S+kbZ
W7MmNfDMdgAh4w+41tYATrxEha6Iu/nNs2MiAtvveVRw
X-Google-Smtp-Source: AMsMyM5cC+dUFXde3jdFxtxSUSlnLCu4WvttKzbSI60IZ0EV1gD2BMeoDiIJ9jDL9MQjl3Zk+Px0GZzQnNrJG4Kgio0=
X-Received: by 2002:a05:6214:4017:b0:4ac:6db5:66f0 with SMTP id
kd23-20020a056214401700b004ac6db566f0mr16504642qvb.105.1663615429570; Mon, 19
Sep 2022 12:23:49 -0700 (PDT)
In-Reply-To: <readability-20220918101045@ram.dialup.fu-berlin.de>
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: <CACL+1avRkrLGaoMPxAh15bJqdqZO+VvvTqFSaOw-Cknp=qpsAw@mail.gmail.com>
X-Mailman-Original-References: <f9f8bac0-9a27-8615-6164-38aa2d9e0fbb@t-online.de>
<CACL+1avBfoS0xDPE1F1CuJDSzDzi_6Ra8FT04c_-Ro1+Uk3OeQ@mail.gmail.com>
<a8db9987-7f35-6b45-1ce9-f17a880dc00a@t-online.de>
<CAPTjJmoPhVkGRqLzCUFDntp2JpR5VX_1qTYJJtj8AnAtDOAWnA@mail.gmail.com>
<CACL+1atihVKMbap8CKEoYuxCsmDnoOAK9N8KY-cn+G5ty2EUHw@mail.gmail.com>
<CAPTjJmrcGWYVr=w9ZMVxxmrU7JT7===5Pe1C2KL5igDK7G8iGw@mail.gmail.com>
<CACL+1atiG4iE4rdDqGMy9rsq=hQV=k0fk+SrcZ0++UmFa2YeCw@mail.gmail.com>
<mailman.460.1663465082.20444.python-list@python.org>
<MethodType-20220918095521@ram.dialup.fu-berlin.de>
<readability-20220918101045@ram.dialup.fu-berlin.de>
 by: Eryk Sun - Mon, 19 Sep 2022 19:23 UTC

On 9/18/22, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
> ram@zedat.fu-berlin.de (Stefan Ram) writes (abbreviated):
>>types.MethodType( function, instance )
>>functools.partial( function, instance )
>>new_method.__get__( instance )
>
> I wonder which of these three possibilities expresses
> the idea of creating a new method from a function and
> an instance most clearly.

Using types.MethodType(function, instance) is the most clear and
correct of the three. Using the function's descriptor __get__() method
is equivalent in terms of the result. That said, the descriptor
protocol is an intermediate-level concept, so manually calling
__get__() isn't friendly to novices or casual users of the language.

Using a functools.partial isn't the expected method type, with
__func__ and __self__ attributes, and, unlike a method, it doesn't
expose the wrapped function's __code__, __name__, __module__, __doc__,
__annotations__, __defaults__, __kwdefaults__, __closure__,
__globals__, or __builtins__. If dynamic inspection matters, using a
functools.partial won't work directly with dis.dis(),
inspect.getfile(), inspect.getsource(), inspect.getdoc(),
inspect.get_annotations(), inspect.getcallargs(), or
inspect.getclosurevars().

Re: How to replace an instance method?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: 2QdxY4Rz...@potatochowder.com
Newsgroups: comp.lang.python
Subject: Re: How to replace an instance method?
Date: Mon, 19 Sep 2022 15:19:01 -0400
Lines: 20
Message-ID: <mailman.471.1663616233.20444.python-list@python.org>
References: <f9f8bac0-9a27-8615-6164-38aa2d9e0fbb@t-online.de>
<CACL+1avBfoS0xDPE1F1CuJDSzDzi_6Ra8FT04c_-Ro1+Uk3OeQ@mail.gmail.com>
<a8db9987-7f35-6b45-1ce9-f17a880dc00a@t-online.de>
<CAPTjJmoPhVkGRqLzCUFDntp2JpR5VX_1qTYJJtj8AnAtDOAWnA@mail.gmail.com>
<CACL+1atihVKMbap8CKEoYuxCsmDnoOAK9N8KY-cn+G5ty2EUHw@mail.gmail.com>
<CAPTjJmrcGWYVr=w9ZMVxxmrU7JT7===5Pe1C2KL5igDK7G8iGw@mail.gmail.com>
<CACL+1atiG4iE4rdDqGMy9rsq=hQV=k0fk+SrcZ0++UmFa2YeCw@mail.gmail.com>
<mailman.460.1663465082.20444.python-list@python.org>
<MethodType-20220918095521@ram.dialup.fu-berlin.de>
<readability-20220918101045@ram.dialup.fu-berlin.de>
<YyjATbeRASltQ1k3@anomaly>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: news.uni-berlin.de wuLOTlolzuQC+3dSimDTxQdMeqiZtSqLiBOFuc6LcQig==
Return-Path: <2QdxY4RzWzUUiLuE@potatochowder.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'okay': 0.07; 'ram': 0.07;
'wrong.': 0.07; 'received:78': 0.09; 'from:addr:2qdxy4rzwzuuilue':
0.16; 'from:addr:potatochowder.com': 0.16; 'instance': 0.16;
'received:136.243': 0.16; 'received:76': 0.16; 'received:78.46':
0.16; 'received:78.46.172': 0.16; 'received:78.46.172.2': 0.16;
'received:sslproxy05.your-server.de': 0.16; 'received:www458.your-
server.de': 0.16; 'received:your-server.de': 0.16; 'skip:> 10':
0.16; 'skip:> 20': 0.16; 'writes': 0.16; 'wrote:': 0.16; 'python':
0.16; 'to:addr:python-list': 0.20; 'subject:How': 0.23;
'received:de': 0.23; 'idea': 0.24; 'python,': 0.25; 'stefan':
0.26; 'creating': 0.27; 'function': 0.27; "doesn't": 0.32;
'received:136': 0.32; "i'm": 0.33; 'requires': 0.34; 'header:In-
Reply-To:1': 0.34; 'one.': 0.35; 'also,': 0.36; 'applying': 0.36;
'methods': 0.39; 'something': 0.40; 'method': 0.61;
'subject:method': 0.69; 'expresses': 0.84; 'leap': 0.84
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <readability-20220918101045@ram.dialup.fu-berlin.de>
X-Authenticated-Sender: 2QdxY4RzWzUUiLuE@potatochowder.com
X-Virus-Scanned: Clear (ClamAV 0.103.6/26663/Mon Sep 19 09:56:35 2022)
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: <YyjATbeRASltQ1k3@anomaly>
X-Mailman-Original-References: <f9f8bac0-9a27-8615-6164-38aa2d9e0fbb@t-online.de>
<CACL+1avBfoS0xDPE1F1CuJDSzDzi_6Ra8FT04c_-Ro1+Uk3OeQ@mail.gmail.com>
<a8db9987-7f35-6b45-1ce9-f17a880dc00a@t-online.de>
<CAPTjJmoPhVkGRqLzCUFDntp2JpR5VX_1qTYJJtj8AnAtDOAWnA@mail.gmail.com>
<CACL+1atihVKMbap8CKEoYuxCsmDnoOAK9N8KY-cn+G5ty2EUHw@mail.gmail.com>
<CAPTjJmrcGWYVr=w9ZMVxxmrU7JT7===5Pe1C2KL5igDK7G8iGw@mail.gmail.com>
<CACL+1atiG4iE4rdDqGMy9rsq=hQV=k0fk+SrcZ0++UmFa2YeCw@mail.gmail.com>
<mailman.460.1663465082.20444.python-list@python.org>
<MethodType-20220918095521@ram.dialup.fu-berlin.de>
<readability-20220918101045@ram.dialup.fu-berlin.de>
 by: 2QdxY4Rz...@potatochowder.com - Mon, 19 Sep 2022 19:19 UTC

On 2022-09-18 at 09:11:28 +0000,
Stefan Ram <ram@zedat.fu-berlin.de> wrote:

> ram@zedat.fu-berlin.de (Stefan Ram) writes (abbreviated):
> >types.MethodType( function, instance )
> >functools.partial( function, instance )
> >new_method.__get__( instance )
>
> I wonder which of these three possibilities expresses
> the idea of creating a new method from a function and
> an instance most clearly.

The first one. And only the first one.

The second one requires too much inside knowledge of Python to make the
leap from currying to instance method.

The third one doesn't even mention the function. Also, in Python, if
I'm applying dunder methods directly (it's okay to write them), then I'm
doing something wrong.

Re: How to replace an instance method?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: eryk...@gmail.com (Eryk Sun)
Newsgroups: comp.lang.python
Subject: Re: How to replace an instance method?
Date: Mon, 19 Sep 2022 16:05:33 -0500
Lines: 35
Message-ID: <mailman.473.1663621537.20444.python-list@python.org>
References: <f9f8bac0-9a27-8615-6164-38aa2d9e0fbb@t-online.de>
<CACL+1avBfoS0xDPE1F1CuJDSzDzi_6Ra8FT04c_-Ro1+Uk3OeQ@mail.gmail.com>
<a8db9987-7f35-6b45-1ce9-f17a880dc00a@t-online.de>
<CAPTjJmoPhVkGRqLzCUFDntp2JpR5VX_1qTYJJtj8AnAtDOAWnA@mail.gmail.com>
<CACL+1atihVKMbap8CKEoYuxCsmDnoOAK9N8KY-cn+G5ty2EUHw@mail.gmail.com>
<CAPTjJmrcGWYVr=w9ZMVxxmrU7JT7===5Pe1C2KL5igDK7G8iGw@mail.gmail.com>
<CACL+1atiG4iE4rdDqGMy9rsq=hQV=k0fk+SrcZ0++UmFa2YeCw@mail.gmail.com>
<mailman.460.1663465082.20444.python-list@python.org>
<MethodType-20220918095521@ram.dialup.fu-berlin.de>
<readability-20220918101045@ram.dialup.fu-berlin.de>
<YyjATbeRASltQ1k3@anomaly>
<CACL+1asUn4agQGT4dGQhRrchj7UUN0y-wXDvVn=HDahn9xFQSg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de DQLEZsSGuxvhhkSVXXbuFArNEbYlR82OI7DyfHozbvwA==
Return-Path: <eryksun@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=PL2gI1Tr;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.047
X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'class,': 0.05; 'ram':
0.07; 'accessed': 0.16; 'instance': 0.16; 'interpreter': 0.16;
'received:209.85.222.180': 0.16; 'received:mail-
qk1-f180.google.com': 0.16; 'skip:> 10': 0.16; 'skip:> 20': 0.16;
'writes': 0.16; 'wrote:': 0.16; 'python': 0.16; 'to:addr:python-
list': 0.20; 'returns': 0.22; 'way.': 0.22; 'subject:How': 0.23;
'idea': 0.24; 'object': 0.26; 'stefan': 0.26; 'creating': 0.27;
'function': 0.27; 'example,': 0.28; "doesn't": 0.32; 'message-
id:@mail.gmail.com': 0.32; 'requires': 0.34; 'header:In-Reply-
To:1': 0.34; 'received:google.com': 0.34; 'one.': 0.35;
'from:addr:gmail.com': 0.35; "it's": 0.37; 'received:209.85':
0.37; 'class': 0.37; 'received:209': 0.39; 'use': 0.39;
'received:209.85.222': 0.39; 'reference': 0.60; 'method': 0.61;
'named': 0.65; 'skip:t 20': 0.66; 'subject:method': 0.69; 'skip:f
20': 0.75; 'attribute': 0.84; 'bind': 0.84; 'expresses': 0.84;
'leap': 0.84; 'type.': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=to:subject:message-id:date:from:references:in-reply-to:mime-version
:from:to:cc:subject:date;
bh=cwkt4Yd0QhBb7SSE3enVal6J380PE8K3nsCF9zNx6sA=;
b=PL2gI1TrZtFlh166HJ9m59ds1zWaf5QWk2IzV8MnGenuhdMbrmfLIA1AHuy5nUxN1h
mqsoY2HEus85Vo4vcgT1zJyRdtjUksuOsBtHDDR4X2nb+gzSeMgn5DJOtHZKX4QOiMpR
nfl8u+ILXxmM6w1LYCwMyhfTaPi+7Fxm0/q0y7NJj8z6HMTkM3PIPe2Blcet0rHrr+ah
uNNW+XeG8LH53iToi/xSq/nrpag6XaSGYlItXyEq2LLUtCR0oNXciMd2SL9lH9vBdQhH
uwKVTLJVX+tEZMSyLGD9ypWcqRGQFZrl8+fN1D46de8Eq51kAXAeLTrC2RgUC+5ENgOJ
vMvg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=to:subject:message-id:date:from:references:in-reply-to:mime-version
:x-gm-message-state:from:to:cc:subject:date;
bh=cwkt4Yd0QhBb7SSE3enVal6J380PE8K3nsCF9zNx6sA=;
b=TSL9mk/X2EBDtkg3Bs6ykYkuGqfsCLhQ24f+x3afFU6ce8OD1bpIPWSOvE75XuZ3AS
h2M9I+MyPskBHGgbUbXgLft6bbgr6My9CkrgJoKXzKzhkez77koyJ+xs+NM40M3O9bbc
5Ceh9Yiv1B10u+Wm/sEHsLGkjC69bt3E4uLNlLQy029bQXAziGnMQzxgogvB3qv9Q1i1
bv04DBbs4195fr8znCNeE/WXCbh1VZozciAHTk97U2lJB5dNkfVwpTw2WTi/jaM0EyQ0
rIVDUCUw/bAnDGtVF+N9mkvI4qluWhd0FCBm57cyAEv1718YfQpQQmWeRdkzK+NQA7Yy
vL8g==
X-Gm-Message-State: ACrzQf2SL23aBT2RB5bp1XSTIOZgl12Rfw4+2JPuYMQFv6Ti7VgutU+s
FQ2v380ZSOFlxfA2HS7NdEd1O6M4M6g4tY21rSbr8pPP
X-Google-Smtp-Source: AMsMyM6h476XgnCgWnXaxWaE6NXuQcaihFlcxACQ8IE4bA99DPXfGfk7G6RQ+39846NhCG7TF6kC40njSxlJRsfcju0=
X-Received: by 2002:a05:620a:4416:b0:6ce:9d3c:2c35 with SMTP id
v22-20020a05620a441600b006ce9d3c2c35mr14704679qkp.78.1663621534113; Mon, 19
Sep 2022 14:05:34 -0700 (PDT)
In-Reply-To: <YyjATbeRASltQ1k3@anomaly>
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: <CACL+1asUn4agQGT4dGQhRrchj7UUN0y-wXDvVn=HDahn9xFQSg@mail.gmail.com>
X-Mailman-Original-References: <f9f8bac0-9a27-8615-6164-38aa2d9e0fbb@t-online.de>
<CACL+1avBfoS0xDPE1F1CuJDSzDzi_6Ra8FT04c_-Ro1+Uk3OeQ@mail.gmail.com>
<a8db9987-7f35-6b45-1ce9-f17a880dc00a@t-online.de>
<CAPTjJmoPhVkGRqLzCUFDntp2JpR5VX_1qTYJJtj8AnAtDOAWnA@mail.gmail.com>
<CACL+1atihVKMbap8CKEoYuxCsmDnoOAK9N8KY-cn+G5ty2EUHw@mail.gmail.com>
<CAPTjJmrcGWYVr=w9ZMVxxmrU7JT7===5Pe1C2KL5igDK7G8iGw@mail.gmail.com>
<CACL+1atiG4iE4rdDqGMy9rsq=hQV=k0fk+SrcZ0++UmFa2YeCw@mail.gmail.com>
<mailman.460.1663465082.20444.python-list@python.org>
<MethodType-20220918095521@ram.dialup.fu-berlin.de>
<readability-20220918101045@ram.dialup.fu-berlin.de>
<YyjATbeRASltQ1k3@anomaly>
 by: Eryk Sun - Mon, 19 Sep 2022 21:05 UTC

On 9/19/22, 2QdxY4RzWzUUiLuE@potatochowder.com
<2QdxY4RzWzUUiLuE@potatochowder.com> wrote:
> On 2022-09-18 at 09:11:28 +0000,
> Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>
>> ram@zedat.fu-berlin.de (Stefan Ram) writes (abbreviated):
>> >types.MethodType( function, instance )
>> >functools.partial( function, instance )
>> >new_method.__get__( instance )
>>
>> I wonder which of these three possibilities expresses
>> the idea of creating a new method from a function and
>> an instance most clearly.
>
> The first one. And only the first one.
>
> The second one requires too much inside knowledge of Python to make the
> leap from currying to instance method.
>
> The third one doesn't even mention the function.

The OP's example named the function "new_method". In general the third
case would be func.__get__(instance). It's how the interpreter binds a
new method when a function from the class hierarchy is accessed as an
instance attribute.

When a function from the class hierarchy is accessed as an attribute
of the class, it's equivalent to calling func.__get__(None, cls),
which just returns a reference to the function. To use the descriptor
protocol to bind a function as a method of the class requires wrapping
it with the classmethod descriptor type. For example,
classmethod(func).__get__(None, cls) returns a method object with
__self__ that references the cls type. Of course, calling
types.MethodType(func, cls) is easier to understand and the preferred
way.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor