Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Loose bits sink chips.


devel / comp.lang.python / Re: PEP Idea: Real private attribute

SubjectAuthor
o Re: PEP Idea: Real private attributeMehrzad Saremi

1
Re: PEP Idea: Real private attribute

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: mehrzad....@gmail.com (Mehrzad Saremi)
Newsgroups: comp.lang.python
Subject: Re: PEP Idea: Real private attribute
Date: Tue, 31 Aug 2021 21:48:37 +0430
Lines: 106
Message-ID: <mailman.532.1630430356.4164.python-list@python.org>
References: <CAPgwy=4Vkauvy+QPnnDus-bU5+bLzh8CHoOraU0Q41URKEqUOg@mail.gmail.com>
<CACo5Rz6DKPVgXoYLGKNOi0Jbg_iFWpCoCX9-XqnLgNuLxqXDAA@mail.gmail.com>
<CAPgwy=5ONuUVQmM7htPENxB6XnD=oZX=LP2hC_M8e_k1G2coBg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de /a9os2KtjqaUlO6zmm92kw6ckPN+zM2qh81IwerQL3yg==
Return-Path: <mehrzad.saremi@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=KO7u2Qlp;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'engineer': 0.02; 'def':
0.04; 'class,': 0.05; "python's": 0.05; 'members,': 0.07;
'url:mailman': 0.09; 'aug': 0.09; 'cc:addr:python-list': 0.09;
'example:': 0.09; 'prints': 0.09; 'skip:@ 20': 0.09; 'skip:` 10':
0.09; 'unlike': 0.09; 'url-ip:67.199.248.12/32': 0.09; 'url-
ip:67.199.248.13/32': 0.09; "can't": 0.14; "'my": 0.16;
'cc:name:python': 0.16; 'imho,': 0.16; 'key.': 0.16; 'level,':
0.16; 'mangling': 0.16; 'members?': 0.16; 'patterns': 0.16;
'pep.': 0.16; 'personally,': 0.16; 'resolution': 0.16;
'resolution,': 0.16; 'subject:Idea': 0.16; 'url:latest': 0.16;
'value"': 0.16; 'wrapper': 0.16; 'wrote:': 0.16; 'url:listinfo':
0.16; 'python': 0.16; 'tue,': 0.18; 'uses': 0.19;
'cc:addr:python.org': 0.19; 'all,': 0.19; 'name.': 0.20; 'url-
ip:188.166.95.178/32': 0.20; 'url-ip:188.166.95/24': 0.20;
'programming': 0.21; 'language': 0.22; 'url-ip:188.166/16': 0.23;
'classes': 0.23; 'creates': 0.23; 'object': 0.23; 'sat,': 0.23;
'skip:_ 10': 0.23; 'anything': 0.24; 'cannot': 0.24; 'idea': 0.25;
'skip:p 30': 0.26; 'cc:2**0': 0.27; 'again,': 0.27; 'url-
ip:188/8': 0.29; "isn't": 0.29; 'it,': 0.31; 'there': 0.31;
'think': 0.31; 'takes': 0.31; 'but': 0.31; 'thanks,': 0.31;
'assume': 0.32; 'objects': 0.32; 'received:209.85.214': 0.32;
'retrieve': 0.32; 'message-id:@mail.gmail.com': 0.33; 'using':
0.33; 'class': 0.33; 'header:In-Reply-To:1': 0.33; 'hold': 0.34;
'subject:PEP': 0.34; 'same': 0.34; 'received:google.com': 0.34;
'example,': 0.35; 'following': 0.35; 'code:': 0.35; 'level.':
0.35; 'url-ip:34.251/16': 0.35; 'url:trace': 0.35;
'from:addr:gmail.com': 0.35; 'applying': 0.37; 'way': 0.37;
'mean': 0.37; 'currently': 0.37; 'received:209.85': 0.38; 'those':
0.38; 'received:209': 0.38; 'use': 0.38; 'does': 0.38; 'put':
0.39; '8bit%:14': 0.39; '[image:': 0.40; 'whether': 0.40;
'example': 0.40; 'normal': 0.60; 'url:u': 0.61; 'simply': 0.62;
'url-ip:67/8': 0.62; 'virus:width="0': 0.62; 'outside': 0.63;
'key': 0.63; 'named': 0.63; 'skip:m 20': 0.64; 'url:png': 0.64;
'pass': 0.64; 'representing': 0.65; 'let': 0.65; 'similar': 0.66;
'right': 0.66; 'skip:n 30': 0.67; 'skip:o 20': 0.67; 'guaranteed':
0.68; 'that,': 0.68; 'adds': 0.69; 'url:logo': 0.69; 'truly':
0.71; '8bit%:6': 0.71; 'private': 0.72; 'discuss': 0.75;
'conflict': 0.77; 'guarantee': 0.77; 'names,': 0.81; 'quality':
0.83; '2021': 0.84; "'type'": 0.84; 'attribute': 0.84;
'subject:private': 0.84; 'tricky': 0.84; 'url:sig': 0.91; 'line,':
0.93; 'url-ip:209/8': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:cc; bh=EOEyu/DYlS6mTXpPZ+fyOEjJ+BfWCVxqUM/UJHkdMQk=;
b=KO7u2Qlpca/wlJCYqjhghfQu/R2v4tZtBeVKAwGluoFfj0O7AEtQhvhAssAjwG02vQ
Cj4MoL93PRAoifN6Ay4X+M5lv6dpK7+0rGeiGH74/GtwDol90bZw3UXqXEjB8BPcIUSP
9CBdV1cpSo0FHNmGRGbg1NNBzCPSfUCTgCvxB5wo9jfbbVZE3Qal6akIO1JrSdUuTP/f
dEW6ZnEERimNWnwC/19wU3bubQZ+DTZDlhUcHz/ZcGxtx4ZpKMthpLmDU/fd9VCpJA3X
omad9a9ab3xCSUHYBGEccfAovOwiMqWKkpvlUufzaQO/10F3yQpPFxNZ4tG+4V4eldoM
eyog==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:cc;
bh=EOEyu/DYlS6mTXpPZ+fyOEjJ+BfWCVxqUM/UJHkdMQk=;
b=oyB5gfwxzhll+deWDpyw0yW7e2ylQ0Lp87eZXW3G1jwmnpBm0C8vlVGNi+0q1KkPvV
vvhLXuuG4E0ksn13RX6Ff2QifgDyVnUhxrztTPtdZju7p7RbDQoCfTJNuKLA34nuDXCa
stF2pnXzugPsy/WAz86FbZu5NWFGk6ckwTs3DNWBKR5D20oMFH0Q1K1T6S/qN7ZWu4zW
5E61OVn7rUZFJ8DoMCdoQsfxW7dYmgmQhmfLEwFljySd29ju7SdqJILB+7ZKGKoEkoD/
iWYWIssaGIaz0EduPwbAChinX1ZEj651EfdWKFf4fPUyfpv22rHMbIzTthXJ+z1tIvAG
lddQ==
X-Gm-Message-State: AOAM5320/KUtKc/OVTHp+hbjy1xRzfRvGY+i99mivdRlL9sW3pHOFZ92
cub+UEvHIsnYpmAXpcyZggBVKEWt4lkq5beSGzHfuzB+FyY=
X-Google-Smtp-Source: ABdhPJzApcarmbZLWHru9Ukilp2LYd/y4mco/OGVLlc1E+azJVlZDZVyqsjvIAfXNS16ms8pY7JTB3jnHCIe9Vxdrh0=
X-Received: by 2002:a17:903:2347:b0:138:8a39:ff6b with SMTP id
c7-20020a170903234700b001388a39ff6bmr5697533plh.20.1630430353180; Tue, 31 Aug
2021 10:19:13 -0700 (PDT)
In-Reply-To: <CACo5Rz6DKPVgXoYLGKNOi0Jbg_iFWpCoCX9-XqnLgNuLxqXDAA@mail.gmail.com>
X-Content-Filtered-By: Mailman/MimeDel 2.1.34
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
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: <CAPgwy=5ONuUVQmM7htPENxB6XnD=oZX=LP2hC_M8e_k1G2coBg@mail.gmail.com>
X-Mailman-Original-References: <CAPgwy=4Vkauvy+QPnnDus-bU5+bLzh8CHoOraU0Q41URKEqUOg@mail.gmail.com>
<CACo5Rz6DKPVgXoYLGKNOi0Jbg_iFWpCoCX9-XqnLgNuLxqXDAA@mail.gmail.com>
 by: Mehrzad Saremi - Tue, 31 Aug 2021 17:18 UTC

Calvin, even if the language offered truly private members?

On Tue, 31 Aug 2021 at 17:31, Calvin Spealman <cspealma@redhat.com> wrote:

> The right way for those decorators to hold some private information, imho,
> isn't to put anything on the decorated object at all, but to use a weak-ref
> dictionary using the target object as a key.
>
> On Sat, Aug 28, 2021 at 5:42 PM Mehrzad Saremi <mehrzad.1024@gmail.com>
> wrote:
>
>> Python currently uses name mangling for double-underscore attributes. Name
>> mangling is not an ideal method to avoid name conflicting. There are
>> various normal programming patterns that can simply cause name conflicting
>> in double-underscore members. A typical example is when a class is
>> re-decorated using the same decorator. The decorator can not take
>> double-underscore members without name conflicts. For example:
>>
>> ```
>> @custom_decorator("a")
>> @custom_decorator("b")
>> class C:
>> pass
>> ```
>>
>> The `@custom_decorator` wrapper may need to hold private members, but
>> Python's current name conflict resolution does not provide any solution
>> and
>> the decorator cannot hold private members without applying tricky
>> programming methods.
>>
>> Another example is when a class inherits from a base class of the same
>> name.
>>
>> ```
>> class View:
>> """A class representing a view of an object; similar to
>> numpy.ndarray.view"""
>> pass
>>
>> class Object:
>> class View(View):
>> """A view class costumized for objects of type Object"""
>> pass
>> ```
>>
>> Again, in this example, class `Object.View` can't take double-underscore
>> names without conflicting with `View`'s.
>>
>> My idea is to introduce real private members (by which I do not mean to be
>> inaccessible from outside the class, but to be guaranteed not to conflict
>> with other private members of the same object). These private members are
>> started with triple underscores and are stored in a separate dictionary
>> named `__privs__`. Unlike `__dict__` that takes 'str' keys, `__privs__`
>> will be a double layer dictionary that takes 'type' keys in the first
>> level, and 'str' keys in the second level.
>>
>> For example, assume that the user runs the following code:
>> ```
>> class C:
>> def __init__(self, value):
>> self.___member = value
>>
>> c = C("my value")
>> ```
>>
>> On the last line, Python's attribute setter creates a new entry in the
>> dictionary with key `C`, adds the value "my value" to a new entry with the
>> key 'member'.
>>
>> The user can then retrieve `c.___member` by invoking the `__privs__`
>> dictionary:
>>
>> ```
>> print(c.__privs__[C]['member']) # prints 'my value'
>> ```
>>
>> Note that, unlike class names, class objects are unique and there will not
>> be any conflicts. Python classes are hashable and can be dictionary keys.
>> Personally, I do not see any disadvantage of using __privs__ over name
>> mangling/double-underscores. While name mangling does not truly guarantee
>> conflict resolution, __privs__ does.
>>
>> Please discuss the idea, let me know what you think about it, whether
>> there
>> are possible disadvantages, and if you think it will be approved as a PEP.
>>
>> Thanks,
>> Mehrzad Saremi
>>
>> AI M.Sc. grad. from AUT
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>>
>
> --
>
> CALVIN SPEALMAN
>
> SENIOR QUALITY ENGINEER
>
> calvin.spealman@redhat.com M: +1.336.210.5107
> [image: https://red.ht/sig] <https://red.ht/sig>
> TRIED. TESTED. TRUSTED. <https://redhat.com/trusted>
>

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor