Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Beware the new TTY code!


devel / comp.lang.python / Re: what's unsafe to do in a __getattr__?

SubjectAuthor
o Re: what's unsafe to do in a __getattr__?Mats Wichmann

1
Re: what's unsafe to do in a __getattr__?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: mat...@wichmann.us (Mats Wichmann)
Newsgroups: comp.lang.python
Subject: Re: what's unsafe to do in a __getattr__?
Date: Mon, 25 Oct 2021 11:05:23 -0600
Lines: 30
Message-ID: <mailman.35.1635181533.23718.python-list@python.org>
References: <476f60c7-0668-3ea1-ef16-f095bdd46eaf@wichmann.us>
<24950.57304.549761.244709@ixdm.fritz.box>
<e3d9c486-3577-7c7b-0411-5b08736fdb68@wichmann.us>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de auJcFVEuDu94I+2JLAU5KwE+jO4KxvUHz4BigZF+Yvuw==
Return-Path: <mats@wichmann.us>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="1024-bit key; unprotected key"
header.d=pobox.com header.i=@pobox.com header.b=VXAW4cis;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.022
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; "python's": 0.05; '"new':
0.09; 'cc:addr:python-list': 0.09; 'skip:` 10': 0.09;
'received:173': 0.13; '(there': 0.16; 'cc:name:python list': 0.16;
'classes,': 0.16; 'dieter': 0.16; 'examine': 0.16; 'mats': 0.16;
'subject:what': 0.16; 'wichmann': 0.16; 'wrote:': 0.16; 'problem':
0.16; "aren't": 0.19; 'implement': 0.19; 'name.': 0.19;
'cc:addr:python.org': 0.20; 'application.': 0.22; 'maybe': 0.22;
'run': 0.23; 'stuff': 0.25; 'cc:2**0': 0.25; 'again,': 0.26;
'classes': 0.26; 'header:User-Agent:1': 0.30; 'raise': 0.31;
"i'll": 0.33; 'there': 0.33; 'header:In-Reply-To:1': 0.34;
'definitely': 0.35; 'special': 0.37; 'using': 0.37; 'class': 0.37;
'received:192.168': 0.37; 'could': 0.38; 'means': 0.38; 'thanks':
0.38; 'methods': 0.39; 'wrote': 0.39; 'difficult': 0.40;
'introduction': 0.61; "there's": 0.61; 'here': 0.62; 'validation':
0.64; 'your': 0.64; 'years': 0.65; 'right': 0.68; 'relevant':
0.73; 'history': 0.75; 'combination': 0.76; 'factors': 0.76;
'reply': 0.77; 'track.': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=message-id
:date:mime-version:subject:to:cc:references:from:in-reply-to
:content-type:content-transfer-encoding; s=sasl; bh=dAc9/PP00MEJ
7wYjQD28Hc37Rj4Y+BW+TmvpgLpzfjM=; b=VXAW4cis9x+wu7q/xs5Yq9SU1z3s
YYZN36Ap3TLDL7Gt2RlSDtc98EzzYxAsZC9hihVe2g8x5FT3Ihj4rMf53ouavdao
CXPvjDgN+DhRko2WRDa0O3QfMNSeEcWrW/TFaanEmE7kP5WV00XuVMiiy64pqzne
2UlR4WrvszV2mFY=
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=wichmann.us;
h=message-id:date:mime-version:subject:to:cc:references:from:in-reply-to:content-type:content-transfer-encoding;
s=2018-07.pbsmtp; bh=dAc9/PP00MEJ7wYjQD28Hc37Rj4Y+BW+TmvpgLpzfjM=;
b=jYtZC07MU9j+nhbG88Ftu9IHb2HF9ZKF+iCEue3GSkjDW18Lq+rvQkh1eqOXuKU059I9xflFSPIV7ZcbapPKsrLmXrabJa3TfyinxEnWbg5B3fIP5M3UGzDfhKLdEJI4+cmL1/ACIegFGV7286MhyeoqbI6OPqHbf/TOT6r8Qvc=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.2.0
Content-Language: en-US
In-Reply-To: <24950.57304.549761.244709@ixdm.fritz.box>
X-Pobox-Relay-ID: BEFE04F6-35B5-11EC-B6C1-F327CE9DA9D6-81526775!pb-smtp20.pobox.com
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.35
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: <e3d9c486-3577-7c7b-0411-5b08736fdb68@wichmann.us>
X-Mailman-Original-References: <476f60c7-0668-3ea1-ef16-f095bdd46eaf@wichmann.us>
<24950.57304.549761.244709@ixdm.fritz.box>
 by: Mats Wichmann - Mon, 25 Oct 2021 17:05 UTC

On 10/25/21 10:48, Dieter Maurer wrote:
> Mats Wichmann wrote at 2021-10-24 19:10 -0600:
>> Have run into a problem on a "mature" project I work on (there are many
>> years of history before I joined), there are a combination of factors
>> that combine to trigger a KeyError when using copy.copy().
>> ...
>> There's a class that's a kind of proxy ...
>
> "Proxying" has become very difficult since the introduction
> of Python's "new style classes" and looking up "special methods"
> on the type rather then the type instance.
>
> This essentially means that the proxy must implement all
> "special methods" that may be relevant to the application.
>
> All special methods start and end with `"__"`.
> Your `__getattr__` could raise an `AttributeError` as soon as
> it is called with such a name.
>

Thanks. Raising an AttributeError here was what I was going to propose
so maybe I'll take your reply as validation I was on the right track.

This stuff was definitely defined in an era before the new-style
classes, might have to examine some other proxying classes to make sure
there aren't other holes...

thanks again,

-- mats

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor