Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Any sufficiently advanced technology is indistinguishable from a rigged demo.


devel / comp.lang.python / Re: Fallback for operator and other dunder methods

SubjectAuthor
o Re: Fallback for operator and other dunder methodsChris Angelico

1
Re: Fallback for operator and other dunder methods

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Fallback for operator and other dunder methods
Date: Wed, 26 Jul 2023 16:40:20 +1000
Lines: 12
Message-ID: <mailman.195.1690353634.23016.python-list@python.org>
References: <2D6F0153-5FAE-49A1-A5B0-23CF9AAED4E7@gmail.com>
<CAPTjJmoRd8psQmC+urJAE5QRM8st3_ihv3v8ODQNjRLEiPHfRA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de BITpS1XQ6IgwsXTatcVUxQ9qHcbZEhS6KXPBiHJhewXg==
Cancel-Lock: sha1:uaMJN3JgCd4Uj0F6gXpgxuf0CAg= sha256:C2c8mXqAoGO7ztZgUAXGXm8hgpjWuSkdCrSX7k/4FEI=
Return-Path: <rosuav@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=dKkTxy5i;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.010
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'jul': 0.04; '(e.g.': 0.05;
'2023': 0.07; 'objects,': 0.09; 'typeerror:': 0.09; 'chrisa':
0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'object,': 0.16; 'wrote:': 0.16; 'to:addr:python-list': 0.20;
'seem': 0.31; 'looked': 0.31; 'python-list': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'but': 0.32; 'subject:for': 0.33;
'there': 0.33; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35;
'special': 0.37; "it's": 0.37; 'this.': 0.37; 'way': 0.38;
'methods': 0.39; 'wed,': 0.39; 'subject:other': 0.69; 'dom': 0.84;
'type.': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20221208; t=1690353632; x=1690958432;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=qiW/i4G32fYNwCgXCU93AnF4nZhAWf9qcTIRFUugaMg=;
b=dKkTxy5iakoeigp1IPsRNUNBcezOjrvfskbu9kW2e8M/A7n7XlSXXdQvzGqC5gOyO7
w9bD/eAeJgwjHrOXpdW9k3XNofjit3qHJ5EEwY1/Cc3WrVigl21GuyJbgBF8pnkF5r+N
lXMXTfrYAeZsGlUeuZriUkxcXY18nmznAK87bHamsNW0tmIgYQxeETktnQehfo2qyc+6
SjHZcesxN7qVrsf2mvco6Ec3hH8R5GfYPFQwKgY8OCKumr4NBWP3GBDyDzt1utr/pZiJ
OmiLQYGCC30VvViKG5iG+Jr25sFTw4k4UqStOE95hdCpgqDCvXRaJ5sJeA0IHK2V/Na0
+oaw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20221208; t=1690353632; x=1690958432;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=qiW/i4G32fYNwCgXCU93AnF4nZhAWf9qcTIRFUugaMg=;
b=PGzBekDUPdvCRMBRSPirJhpA7J+GQJvALBYUGyyUIF20A+3BJ9i5RMBzRSTwqUGXcV
o3xwbTgdILyb2+p9jRm8TKUxBdL8UZWigSqVcowpVhdrANRTVKejV/h/a/aTGUca3hjT
SgO1BM/w05BXsG80dX8W95O4ouATsoMX4OtEkQqiveHNl5tsMCWzSnM7PsfgwVCl3ue2
v25Xio0l4HelZWsoouQ2+7e9miJbN1bQbslQFayrLXnuufxLWSqQUWed7/kf0mkvwMPQ
w156XUsFQ4gPhiUItNU82w/J5Tt+Ol4FQ3JYEZnJlPVVNgVxg7NzFGq0m9REFvJrR+tH
KzIQ==
X-Gm-Message-State: ABy/qLbA/gMdH6Wo57Luw7Ea3LYaUjvhMdbFrK+7ceSRQ8bXUle6APQk
fCIVIEc1e/RwyJBLes31ThdtuLzTeh2daiXYQB3co1GK
X-Google-Smtp-Source: APBJJlEQl/CYOZtDij+S0KIstS780ABsANg5yyQkqGfruIp9E/P3OFGnd8jkqfB4U5+TjOuF3SW3A2MpFirSyOZpyHI=
X-Received: by 2002:a17:906:7791:b0:989:450:e585 with SMTP id
s17-20020a170906779100b009890450e585mr809243ejm.45.1690353631677; Tue, 25 Jul
2023 23:40:31 -0700 (PDT)
In-Reply-To: <2D6F0153-5FAE-49A1-A5B0-23CF9AAED4E7@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: <CAPTjJmoRd8psQmC+urJAE5QRM8st3_ihv3v8ODQNjRLEiPHfRA@mail.gmail.com>
X-Mailman-Original-References: <2D6F0153-5FAE-49A1-A5B0-23CF9AAED4E7@gmail.com>
 by: Chris Angelico - Wed, 26 Jul 2023 06:40 UTC

On Wed, 26 Jul 2023 at 12:23, Dom Grigonis via Python-list
<python-list@python.org> wrote:
> print(a + 1) # TypeError: unsupported operand type(s) for +: 'A' and 'int'
>
> Is there a way to achieve it without actually implementing operators?
> I have looked at Proxy objects, but they do not seem suited to achieve this. (e.g. wrapt)

These kinds of special methods are not looked up on the object, but on
the type. It's more like type(a).__add__(a, 1). So you would need a
metaclass for this.

ChrisA

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor