Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

BASIC is the Computer Science equivalent of `Scientific Creationism'.


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

SubjectAuthor
* extend behaviour of assignment operatorGuenther Sohler
`- Re: extend behaviour of assignment operatorStefan Ram

1
extend behaviour of assignment operator

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: guenther...@gmail.com (Guenther Sohler)
Newsgroups: comp.lang.python
Subject: extend behaviour of assignment operator
Date: Tue, 9 Jan 2024 08:14:31 +0100
Lines: 24
Message-ID: <mailman.1.1704895573.15798.python-list@python.org>
References: <CAASeUHopbgPeqdC_bbvQSiVnTb0y=20BJz-2T-82Huakhu7Bdw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de UjDY2itn//OrgwDZhIw68AJHLIYi91nsdw8JKhAs1L+Q==
Cancel-Lock: sha1:R1FIOXgJ2jxuf3t6RZiTqxmOaNA= sha256:dqQPV02kA8YXCAYBj3wIFKGGfTEP7yFnBOn8Qcg3uoE=
Return-Path: <guenther.sohler@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=ASMOMbvw;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: UNSURE 0.283
X-Spam-Level: **
X-Spam-Evidence: '*H*': 0.54; '*S*': 0.11; 'variable': 0.05;
'operators': 0.09; 'behaviour': 0.16; 'hints': 0.16; 'to:addr
:python-list': 0.20; 'code': 0.23; 'run': 0.23; "i'd": 0.24;
'message-id:@mail.gmail.com': 0.32; 'but': 0.32;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35;
'changes': 0.39; 'use': 0.39; 'should': 0.40; 'shall': 0.61;
'skip:b 10': 0.63; 'extend': 0.64; 'improved': 0.64; 'url:a':
0.64; 'url:name': 0.64; 'your': 0.64; 'url-ip:lookup error': 0.70;
'effective': 0.78; 'subject:assignment': 0.91; 'url:b': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1704784482; x=1705389282; darn=python.org;
h=to:subject:message-id:date:from:mime-version:from:to:cc:subject
:date:message-id:reply-to;
bh=BpgoZUWAAAvC3v6jYFsKAwKcCouCZ0NE4kSFtL0fXpY=;
b=ASMOMbvwq7UmvP/MRiiABZdcNoVHgSFR9ypyFibXOTtBtneNFI9UsMlqKTMFFNqT9N
9lixfnOVVzLBkEKxx67RcXTvKFK3ItIUeccuHenvu+Uu4baeAIGPEUZmGeWEPv6GlSNB
MaGhrtzuKln1rFrhG99CHauHratKND1HkMsmlQge7tmaoZ1zyJQWGopwVkQG9FkRn8Yw
GmNV//zy/ZLc2rp7IBRccHEddqVkdHFp59w6KQ+0UqgatckQvhHQV9jr31sjuyFtO2MJ
lC9zcWatzj0yLcI8Qqik4D4fw7KE/aT6YinhXvqzt5+qTTRqPzRve+n/StU1iTG6O/4r
IAgg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1704784482; x=1705389282;
h=to:subject:message-id:date:from:mime-version:x-gm-message-state
:from:to:cc:subject:date:message-id:reply-to;
bh=BpgoZUWAAAvC3v6jYFsKAwKcCouCZ0NE4kSFtL0fXpY=;
b=mICg3oXn7hfllamP5W9OJ1wYxfR+F89G6dXYsTLpm0lSCRJGFmvDas8TI0xvEPW/9m
rN5IkFOdQ1Lo/9gaXdljqX9eljHYm0zM8X3ok8H2EnXH5RMj92pO2oXeD7ONztqkawqL
5FMpvP+iV+y8J41xkbnhtOByhMHTDOYeMhxAiHnXNgIcmzekC3wDY4f7U78nUI4ArQeF
0zFdmw/GEGWRXTfhGTxlp1xBUJgCRn5gPGe9irOxD3YjJPIWPef9O+lXIUe/GthPLbgT
BUzs8W6sfonSQqJKtw46xDgOi65Z0nn2ivYrN+RttKXXizt7IiBowcCk8lC9AbC7rBFt
T1Pw==
X-Gm-Message-State: AOJu0YxEWVFVfRaJf6Ks5TSNAuaeEQJqVGW4OPI5fAwwsyGngv3HT59l
SFHINOyjowV4z5b2cmY+YDtNpwTI0Y6avFZOxIz+R7AnrZg=
X-Google-Smtp-Source: AGHT+IGmRPSXAkQWSRo2m9RLntiofz2yo0r9g8tsPIcdTD6s4+EHSYZbjWooBjFaLVeF/JG9/MsqAazriMPpwNgWW5k=
X-Received: by 2002:a05:6402:1763:b0:555:30e3:c577 with SMTP id
da3-20020a056402176300b0055530e3c577mr2428494edb.85.1704784482207; Mon, 08
Jan 2024 23:14:42 -0800 (PST)
X-Mailman-Approved-At: Wed, 10 Jan 2024 09:06:11 -0500
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: <CAASeUHopbgPeqdC_bbvQSiVnTb0y=20BJz-2T-82Huakhu7Bdw@mail.gmail.com>
 by: Guenther Sohler - Tue, 9 Jan 2024 07:14 UTC

Hi,

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.

effective code should be:

a=cube([10,1,1])
a.name='a'

b=a
b.name='b' # i am aware that a.name also changes

can decorators also be used with assignment operators ?

thank you for your hints

Re: extend behaviour of assignment operator

<ast-20240110203859@ram.dialup.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: extend behaviour of assignment operator
Date: 10 Jan 2024 19:40:49 GMT
Organization: Stefan Ram
Lines: 25
Expires: 1 Dec 2024 11:59:58 GMT
Message-ID: <ast-20240110203859@ram.dialup.fu-berlin.de>
References: <mailman.1.1704895573.15798.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 +Pf7wNw/likkiD+6EA6T6wFVVlKbjly4xtrKt6iZZmAPX7
Cancel-Lock: sha1:5mbNTkq1fsL6LI0qgVzSQ83aoMI= sha256:adftsrYxZ5bpmhBcwzaSanHH1mK5DQ7DLVSUYYLXFOs=
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 - Wed, 10 Jan 2024 19:40 UTC

Guenther Sohler <guenther.sohler@gmail.com> writes:
>i'd like to extend the behaviour of the assignment operator

The following attempt is just a proof of concept, as it will
not handle properly all possible code. To do something similar
in a more general way, use "import ast", parse the code into
an AST and then search the AST for assignements and insert
code to change the name attribute after them.

import re

class thing: pass # all things pass

code = r'''
a = thing()
print( a.name )
b = a
print( b.name )
'''

code = \
re.sub\
( r'((?:^|\n)(\s*)([\w_]+)\s*=.*(\n|$))', r'\1\2\3.name="\3"\n', code )
exec( code )

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor