Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"If it ain't broke, don't fix it." -- Bert Lantz


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

SubjectAuthor
o RE: How to replace an instance method?<avi.e.gross

1
RE: How to replace an instance method?

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

  copy mid

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

  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:
Newsgroups: comp.lang.python
Subject: RE: How to replace an instance method?
Date: Sat, 17 Sep 2022 20:28:05 -0400
Lines: 47
Message-ID: <mailman.458.1663460891.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>
<004e01d8caf5$857fe7a0$907fb6e0$@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de bX8OqEojG1k2AXf4B25t9AystfOBLDl0+E3ejeMG394g==
Return-Path: <avi.e.gross@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=mLV2g+Xp;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '17,': 0.04; 'argument':
0.04; 'knows': 0.04; '2022': 0.05; 'sun,': 0.07; 'thing.': 0.07;
'underlying': 0.07; 'angelico': 0.09; 'fundamental': 0.09;
'received:209.85.219': 0.09; 'though.': 0.09; 'unlike': 0.09;
'url:mailman': 0.15; 'accessed': 0.16; 'attributes': 0.16;
'chrisa': 0.16; 'eryk': 0.16; 'inspecting': 0.16; 'instance':
0.16; 'method?': 0.16; 'sees': 0.16; 'sept': 0.16; 'sounds': 0.16;
'whichever': 0.16; 'wrapper': 0.16; 'wrote:': 0.16; 'python':
0.16; 'message-id:@gmail.com': 0.18; 'to:addr:python-list': 0.20;
'basically': 0.22; 'skip:_ 10': 0.22; 'subject:How': 0.23; 'skip:-
10': 0.25; 'url-ip:188.166.95.178/32': 0.25; 'url-
ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'programming':
0.25; 'url-ip:188.166/16': 0.25; 'object': 0.26; "isn't": 0.27;
'function': 0.27; 'chris': 0.28; 'fact': 0.28; 'sense': 0.28;
'url-ip:188/8': 0.31; 'modified': 0.32; 'python-list': 0.32;
'but': 0.32; 'same': 0.34; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'one.': 0.35; 'yes,': 0.35;
'from:addr:gmail.com': 0.35; 'also,': 0.36; 'functions': 0.36;
'really': 0.37; 'using': 0.37; 'received:209.85': 0.37; 'this.':
0.37; 'received:209': 0.39; 'two': 0.39; 'received:100': 0.39;
'still': 0.40; 'both': 0.40; 'in,': 0.60; 'method': 0.61; 'from:':
0.62; 'to:': 0.62; 're:': 0.64; 'thus': 0.64; 'your': 0.64;
'back': 0.67; 'choose': 0.67; 'that,': 0.67; 'attached': 0.68;
'functional': 0.69; 'subject:method': 0.69; 'them,': 0.70;
'truly': 0.70; 'sent:': 0.78; 'attribute': 0.84; 'factory': 0.84;
'falls': 0.84; 'saturday,': 0.84; 'type,': 0.84; 'type.': 0.84;
'emphasizes': 0.91; 'locked': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=content-language:thread-index:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:from:to:cc:subject:date;
bh=gY4KUX9kFjy2XhbeEckCLyk+CE8Lu5hMznWYzkIKtto=;
b=mLV2g+XpY2M5ITWTb5JB0asKVSxJFCl775FfYfO13vwBZcbnoAML1NsCpLKuJjurY6
BMzr0+AXF2NawcdMZg+hOIPeGaMaR/q0IfQh7GeFzB6261DZ60a+vZoOERv3wBF4Hgos
EbuBF0QbjLRDxUudnaTK8+ApBmW4PUUVhiaKku1uep9Tup4/qv/5u4lrEEGs+JZbgt/U
DMMzCvuuFtZ5EXbLPV1P1ewa40nbOr/iIhciLhWVt2d4el/BSowhoeWD21ap714dUFkN
zC1Nx6z7oFnd+z7p+4ZfCvrvUIsVeof17jHun6lxfhgKPz/SSEl+lPXFnMC3XGZTH3Dy
EfNQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=content-language:thread-index:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:x-gm-message-state:from:to:cc:subject:date;
bh=gY4KUX9kFjy2XhbeEckCLyk+CE8Lu5hMznWYzkIKtto=;
b=iZzjm8s07zxyrCVvIJ2nEMjehceUdxL6mlykr0PF/80WgotjgdLitRUzaNkUVJQ+ux
A+dSCTwxDW4D4fdasdfubHlOZp+qE13/GCFI+PWtgsZ+Mpd686xyOBZm0FYGvAixeNHf
hZ+9XhZUq3wQLdY2rgO9c4gCXFSuCrtyEFgpbFzfKAhD0r8zzOJPSwTeC2BwXLWWQicC
8dnkvFuSMv+ZqKl4kX1rUmRD24ywnMvFzcO3yMb9KDy5+l+L7Oa7WtaldW6YHVDH/pJb
92UWtPDunpIccrcVyK/pT5YkIri3R9ipmWld9cXiywswpZS/tjDsM83TpMJACT/tqEQ0
+3bQ==
X-Gm-Message-State: ACrzQf0OSSBysPUguFTLDYiHM/TbV97942654Yq69BZB1j8lAiDBIy7D
CeevwbB7Gq29lM1bIsd6zSwR+l8mFbM=
X-Google-Smtp-Source: AMsMyM64xdvvWF0wfVZG4GVNdF2zTzPkgTpvAM7NCHUv0O9pwb9y9V6/1Ifkju9zoUNIU1JbV+UCfQ==
X-Received: by 2002:a05:6214:20e5:b0:4aa:b01f:471f with SMTP id
5-20020a05621420e500b004aab01f471fmr9659597qvk.38.1663460888538;
Sat, 17 Sep 2022 17:28:08 -0700 (PDT)
In-Reply-To: <CAPTjJmrcGWYVr=w9ZMVxxmrU7JT7===5Pe1C2KL5igDK7G8iGw@mail.gmail.com>
X-Mailer: Microsoft Outlook 16.0
Thread-Index: AQKtiHwe9rnzGX09Mf+ES3mKRMBV+gMm9GhRAPRxjmMBga5bkwEj6AhJAa/lMxur91JbkA==
Content-Language: en-us
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: <004e01d8caf5$857fe7a0$907fb6e0$@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: - Sun, 18 Sep 2022 00:28 UTC

>From your description, Chris, it sounds like the functional programming
technique often called currying. A factory function is created where one (or
more) parameters are sort of frozen in so the user never sees or cares about
them, and a modified or wrapped function is returned. In this case, the
function now knows what object it is attached to as this.

-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On
Behalf Of Chris Angelico
Sent: Saturday, September 17, 2022 8:21 PM
To: python-list@python.org
Subject: Re: How to replace an instance method?

On Sun, 18 Sept 2022 at 09:37, Eryk Sun <eryksun@gmail.com> wrote:
>
> On 9/17/22, Chris Angelico <rosuav@gmail.com> wrote:
> >
> > The two are basically equivalent. Using functools.partial emphasizes
> > the fact that all you're doing is "locking in" the first parameter;
> > using the __get__ method emphasizes the fact that functions are,
> > fundamentally, the same thing as methods. Choose whichever one makes
> > sense to you!
>
> Functions are really not "fundamentally, the same thing as methods".
> They're only the same in that they're both callable. Also, a method's
> __getattribute__() falls back on looking up attributes on the
> underlying function (i.e. the method's __func__), such as inspecting
> the __name__ and __code__. A fundamental difference is that, unlike a
> function, a method is not a descriptor. Thus if a method object is set
> as an attribute of a type, the method does not rebind as a new method
> when accessed as an attribute of an instance of the type.

An unbound method in Python 2 was distinctly different from a function, but
in Python 3, they really truly are the same thing. A bound method object is
a small wrapper around a function which binds its 'self' parameter; that's a
distinction, but not a fundamental one.
Yes, a bound method isn't a descriptor; that's not really a huge difference
either, though.

A method IS a function. A bound method is a function with one argument
locked in, but still a function.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor