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: extend behaviour of assignment operator

SubjectAuthor
o extend behaviour of assignment operatorDieter Maurer

1
Re: extend behaviour of assignment operator

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!rocksolid2!news.neodome.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: dieter@handshake.de (Dieter Maurer)
Newsgroups: comp.lang.python
Subject: Re: extend behaviour of assignment operator
Date: Wed, 10 Jan 2024 19:44:31 +0100
Lines: 60
Message-ID: <mailman.2.1704913512.15798.python-list@python.org>
References: <CAASeUHopbgPeqdC_bbvQSiVnTb0y=20BJz-2T-82Huakhu7Bdw@mail.gmail.com>
<26014.58767.753936.352783@ixdm.fritz.box>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de dq9IpGOEIz+6jwZE4KV98AOq/W1mF9/M6lsNPTaCLPwg==
Cancel-Lock: sha1:05lMkS0XkTz+HtkjQIgf6XMpdFA= sha256:78wlZtZpnnriMpsFIb0KYBHJK9XeF1g0bU+1PpjYrRk=
Return-Path: <dieter@handshake.de>
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.006
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'def': 0.04; 'knows': 0.04;
'(e.g.': 0.05; 'cc:addr:python-list': 0.09; 'implicit': 0.09;
'objects,': 0.09; 'skip:_ 20': 0.09; 'skip:` 10': 0.09; 'skip:`
20': 0.09; 'typeerror:': 0.09; 'cc:no real name:2**0': 0.14;
'import': 0.15; 'accessed': 0.16; 'behaviour': 0.16; 'implements':
0.16; 'instance': 0.16; 'similar.': 0.16; 'wrapper': 0.16;
'cc:addr:python.org': 0.20; 'maybe': 0.22; 'code': 0.23; 'run':
0.23; 'received:de': 0.23; "i'd": 0.24; '(and': 0.25; 'cc:2**0':
0.25; 'classes': 0.26; 'object': 0.26; 'else': 0.27; 'fact': 0.28;
'mostly': 0.28; 'but': 0.32; 'header:In-Reply-To:1': 0.34;
'following': 0.35; 'special': 0.37; 'class': 0.37; 'could': 0.38;
'use': 0.39; 'wrote': 0.39; 'something': 0.40; 'shall': 0.61;
'true': 0.63; 'pass': 0.64; 'extend': 0.64; 'improved': 0.64;
'your': 0.64; 'look': 0.65; 'header:Received:6': 0.67;
'implemented': 0.76; 'attribute': 0.84; 'method,': 0.84;
'received:88': 0.84; 'similarly': 0.84; 'subject:assignment':
0.91; 'acquisition': 0.93
In-Reply-To: <CAASeUHopbgPeqdC_bbvQSiVnTb0y=20BJz-2T-82Huakhu7Bdw@mail.gmail.com>
X-Mailer: VM 8.0.12-devo-585 under 21.4 (patch 24) "Standard C" XEmacs Lucid
(x86_64-linux-gnu)
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: <26014.58767.753936.352783@ixdm.fritz.box>
X-Mailman-Original-References: <CAASeUHopbgPeqdC_bbvQSiVnTb0y=20BJz-2T-82Huakhu7Bdw@mail.gmail.com>
 by: Dieter Maurer - Wed, 10 Jan 2024 18:44 UTC

Guenther Sohler wrote at 2024-1-9 08:14 +0100:
>when i run this code
>
>a = cube([10,1,1])
>b = a
>
>i'd like to extend the behaviour of the assignment operator
>a shall not only contain the cube, but the cube shall also know which
>variable name it
>was assigned to, lately. I'd like to use that for improved user interaction.

`Acquisition` (--> `PyPI`) implements something similar.

It does not work for variables -- but for attribute access.
Look at the following code:

```
from Acquisition import Implicit

class AccessAwareContainer(Implicit):
...

class AccessAwareContent(Implicit):
...

container = AccessAwareContainer()
container.content = AccessAwareContent()
```

When you now assign `content = container.content`, then
`content` knows that it has been accessed via `container`.

If fact `content` is not a true `AccessAwareContent` instance
but a wrapper proxy for it. It mostly behaves like an
`AccessAwareContent` object but has additional information
(e.g. it knows the access parent).

It works via a special `__getattribute__` method, essentially
implemented by:

```
def __getattribute__(self, k):
v = super().__getattribute__(k)
return v.__of__(self) if hasattr(v, "__of__") else v
```

Your use case could be implemented similarly (again not for variables
and all objects, but for special classes (and maybe special objects)).

Your `__getattribute__` could look like:
```
def __getattribute__(self, k):
v = super().__getattribute__(k)
try:
v.name = k
except TypeError: pass
return v
```


devel / comp.lang.python / Re: extend behaviour of assignment operator

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor