Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Computers are like air conditioners. Both stop working, if you open windows. -- Adam Heath


devel / comp.lang.python / Re: __set_name__ equivalent for instance

SubjectAuthor
o Re: __set_name__ equivalent for instanceDom Grigonis

1
Re: __set_name__ equivalent for instance

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

  copy mid

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

  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: dom.grig...@gmail.com (Dom Grigonis)
Newsgroups: comp.lang.python
Subject: Re: __set_name__ equivalent for instance
Date: Thu, 16 Nov 2023 21:11:18 +0200
Lines: 41
Message-ID: <mailman.273.1700161881.3828.python-list@python.org>
References: <C459D5FA-DE60-4FA5-B7CF-284CB32D8DEE@gmail.com>
<25942.22823.215688.837713@ixdm.fritz.box>
<1E96390D-219C-4064-9C46-4F7BED89E324@gmail.com>
<25942.26334.931807.146304@ixdm.fritz.box>
<AAE2E7E5-52A8-489F-B9C7-1C57BA8FD959@gmail.com>
Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\))
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de xb+abACCRZ+HTSQsJgunIg4MzMhq5JjHeJ9YKqsK0N0g==
Cancel-Lock: sha1:VkFu5+6d+HSBCRDvWcNV3a/CgWY= sha256:xhgrTEHBxETcU2++6VXSqL6nJA05KYDj43v0m1UkHNc=
Return-Path: <dom.grigonis@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=hbhDL9m8;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.031
X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'binding': 0.09; 'cc:addr
:python-list': 0.09; 'skip:` 10': 0.09; 'skip:` 20': 0.09;
'that.': 0.15; '21:00,': 0.16; 'arbitrary': 0.16;
'cc:name:python': 0.16; 'creation,': 0.16; 'dieter': 0.16;
'instance': 0.16; 'option.': 0.16; 'preferably': 0.16;
'received:apple': 0.16; 'received:smtpclient.apple': 0.16;
'wrote:': 0.16; 'message-id:@gmail.com': 0.18; 'implement': 0.19;
'cc:addr:python.org': 0.20; 'maybe': 0.22; '(and': 0.25;
'cc:2**0': 0.25; 'tried': 0.26; 'function': 0.27; 'done': 0.28;
'approach': 0.31; 'think': 0.32; 'exploring': 0.32; 'but': 0.32;
'subject:for': 0.33; 'there': 0.33; 'focus': 0.33; 'header:In-
Reply-To:1': 0.34; 'received:google.com': 0.34; 'yes,': 0.35;
'from:addr:gmail.com': 0.35; 'class': 0.37; 'way': 0.38; 'use':
0.39; 'finding': 0.39; 'methods': 0.39; 'wrote': 0.39; 'still':
0.40; 'case.': 0.40; 'whenever': 0.40; 'want': 0.40; 'method':
0.61; 'your': 0.64; 'interested': 0.68; 'know.': 0.68; 'during':
0.69; 'currently,': 0.69; 'allowed.': 0.84; 'dom': 0.84;
'inherit': 0.84; 'received:88': 0.84; 'thus,': 0.84; 'type,': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1700161880; x=1700766680; darn=python.org;
h=to:references:message-id:content-transfer-encoding:cc:date
:in-reply-to:from:subject:mime-version:from:to:cc:subject:date
:message-id:reply-to;
bh=26oTDZ76+juF+YmsqVW+tWeN9qVrihPKLSRHDPt35kg=;
b=hbhDL9m8RI9UG8ngFS+/CApVotpmMomjUoaM6rDQfqph9EX3eA+/saiUeI6U9ah9XP
L0An+DZ2tV/zTi6hu16urR0mO2LWJ1ULVK3TYiEYN0tQCss406ekJ93Rmeqx2YHNpGu0
V8+v6bspuBEGBzrcgz5G68LyWzDFjk/Nea0mtDOzo/jc9BaLoO1IhVzCT8vQ8mDSXd4A
lPi0oem6McsnbSPw+exa3kcKBkmYnWFSxFSPmi2EZxms7/1yhSnmiRLJ6Rd/z0dO8twi
bzvkLBp9NKitZJV7KOZ9PNB0jKkTapLPSCA/67mqeMYq6iPLZwvU3/zdwAQJ6r8NOE4u
O9ow==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1700161880; x=1700766680;
h=to:references:message-id:content-transfer-encoding:cc:date
:in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc
:subject:date:message-id:reply-to;
bh=26oTDZ76+juF+YmsqVW+tWeN9qVrihPKLSRHDPt35kg=;
b=Sw8bPtWlo3uPx5ppfQpYt6WURlZUOGBC2tOl7a8F4JS4/nPF+eACgod4DbaCbRn1UJ
u9FjQ0xg0fD6zpDpxpjv0eVcCsZMo8nuZ/uDoMCdzyK7k6/vmqIBSOPIcZPqeAqMiqNX
QEdUs8/FxSv+0/lzzKqFw5k3yiS4Pe0NKApsvnrjRMkKz/WFVmhYbD4bxI0Dfxq+K3GN
pd3ZFMCm6D6noCgiRdvYzav3C/GByiMWkvwMfMzC21ZyONaUSe4VwqL8E+ap7PLb34if
/MI4a7110a6PG/J+DBDxI4WIv7WAfViVza/Z6coemeedOqfL3my/7DwO6jV6xpeSKWjD
9YYg==
X-Gm-Message-State: AOJu0YzmKwmf2L/T5DJ+F777TP/BphheY0+IWc18Y4JCxUZxkZlNgJJs
3muy+1ts71fPXsbafiG4u6M=
X-Google-Smtp-Source: AGHT+IE3WgS9O8IoHFbDYNnMp+qR0DuUw9I8FfMAgEANqg6FmDzQwivpn7aGFUmAAekZSrUh/AEItg==
X-Received: by 2002:a17:907:36c7:b0:9c6:287d:c59d with SMTP id
bj7-20020a17090736c700b009c6287dc59dmr16480995ejc.28.1700161879874;
Thu, 16 Nov 2023 11:11:19 -0800 (PST)
In-Reply-To: <25942.26334.931807.146304@ixdm.fritz.box>
X-Mailer: Apple Mail (2.3654.120.0.1.15)
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: <AAE2E7E5-52A8-489F-B9C7-1C57BA8FD959@gmail.com>
X-Mailman-Original-References: <C459D5FA-DE60-4FA5-B7CF-284CB32D8DEE@gmail.com>
<25942.22823.215688.837713@ixdm.fritz.box>
<1E96390D-219C-4064-9C46-4F7BED89E324@gmail.com>
<25942.26334.931807.146304@ixdm.fritz.box>
 by: Dom Grigonis - Thu, 16 Nov 2023 19:11 UTC

> On 16 Nov 2023, at 21:00, Dieter Maurer <dieter@handshake.de> wrote:
>
> Dom Grigonis wrote at 2023-11-16 20:12 +0200:
>> What I am interested in is a callback.
>> Preferably just after methods get bound. So in `object.__new__`.
>
>> I have done it via metaclass, but it is not ideal as there would be too much overhead.
>>
>> I think what I am looking for is custom method binding.
>
> Methods are not bound during instance creation, they are bound during
> access.

Good to know. What is the criteria for binding then? Does it check if its type is `vanilla` function? If yes, is there any way to simulate it for arbitrary object?

I have tried inheriting from function type, but not allowed.

> You can use descriptors to implement "custom method binding".
>
> Descriptors are defined on the class (and do not behave as
> descriptors when defined on instances).
> Thus, you would need a metaclass or `__inist_subclass__` is you
> want your "custom method binding" globally.

Yes, I have tried that. This works well. But maybe will be useful for another case.

Currently, the focus is decorators that can be used on arbitrary methods. Needing to inherit and add metaclasses whenever I want to decorate is not an option.

I think I will continue with descriptor approach and am slowly finding route to get where I need to, but still exploring options.

Regards,
DG

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor