Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Logic is the chastity belt of the mind!


devel / comp.lang.python / Re: Seeking deeper understanding of python equality (==)

SubjectAuthor
o Re: Seeking deeper understanding of python equality (==)Sam Ezeh

1
Re: Seeking deeper understanding of python equality (==)

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: sam.z.e...@gmail.com (Sam Ezeh)
Newsgroups: comp.lang.python
Subject: Re: Seeking deeper understanding of python equality (==)
Date: Fri, 6 May 2022 18:31:05 +0100
Lines: 100
Message-ID: <mailman.325.1651858281.20749.python-list@python.org>
References: <CAMA-GnV5+Z-Q7vo+G2x32ytjiVsuCLGxR2NX=BAQPrWGhOHH4Q@mail.gmail.com>
<CAD+b3HgW6u9+PN--k8CYeWF=ZNg6GX+Tu6hHy_qh9G6y3u9EMQ@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de dj1zyuYKOddVuBNTWVpc/QVuofR5czyG9rSml6kYT4Qw==
Return-Path: <sam.z.ezeh@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=DqFMiW3o;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'url-ip:140.82/16': 0.03;
'def': 0.04; '2022': 0.05; 'subject:python': 0.06; 'debugging':
0.07; 'explanation': 0.07; 'comparison': 0.09; 'knowledge.': 0.09;
'url:github': 0.14; 'import': 0.15; 'url:mailman': 0.15; 'url-
ip:140/8': 0.15; 'cat': 0.16; 'expected.': 0.16; 'occur.': 0.16;
'permitted': 0.16; 'program:': 0.16; 'python3': 0.16;
'url:cpython': 0.16; 'warning:': 0.16; 'wrote:': 0.16; 'python':
0.16; 'to:addr:python-list': 0.20; 'fri,': 0.22; 'ran': 0.22;
'install': 0.23; 'code': 0.23; 'run': 0.23; 'idea': 0.24; 'url-
ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24': 0.25;
'url:listinfo': 0.25; 'url-ip:188.166/16': 0.25; 'space': 0.26;
'library': 0.26; 'received:209.85.210': 0.29; 'recently': 0.29;
'error': 0.29; 'url-ip:188/8': 0.31; 'think': 0.32; 'assume':
0.32; 'subject:skip:u 10': 0.32; 'message-id:@mail.gmail.com':
0.32; 'but': 0.32; "i'm": 0.33; "i'll": 0.33; 'able': 0.34;
'same': 0.34; 'header:In-Reply-To:1': 0.34; 'received:google.com':
0.34; 'trying': 0.35; 'from:addr:gmail.com': 0.35; 'also,': 0.36;
'source': 0.36; 'change': 0.36; 'using': 0.37; 'received:209.85':
0.37; 'class': 0.37; 'received:209': 0.39; 'single': 0.39;
'still': 0.40; 'explain': 0.40; 'want': 0.40; 'method': 0.61;
'skip:o 10': 0.61; 'skip:r 20': 0.64; 'thus': 0.64; 'compare':
0.69; 'skip:/ 10': 0.69; 'surface': 0.69; 'dis': 0.84; 'skip:"
40': 0.84; 'steps.': 0.84; 'subject:Seeking': 0.84; 'priority.':
0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:content-transfer-encoding;
bh=90X3DjF25HBLYunkzOjUl1elYfvpsjhtC3zvCwP9TBQ=;
b=DqFMiW3odxi7gOog/cVClFj/bo78KFLp0/7LJBN4bL2cYkwXtdr8vuPjmPxRyl2lz7
mINX+IF0QTFGn9Q903plohLtPWm2jQ4trTxYVAW8hr2nbrtu1bTyQL1+RsckzHycYy8f
rSXh8mELjYgQLXYTlfHeYBBkP2QuiIh/Iy/NGuQgUtEqE/PD5s+CgSIgMrsmNV68xpE9
07s9fQKtJy2l/mUJ+w53V+rfQYSRcc26HOtlMgqCxM4yzfoaVOGNZ4AEhx8rwi17erEe
AmPL73iWpcY1QRsZP6OhuQ2CFiBoFbb0NgXhp2yzRCLD54NA4qAVkH972h0PWuaTzi2P
5iTw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:content-transfer-encoding;
bh=90X3DjF25HBLYunkzOjUl1elYfvpsjhtC3zvCwP9TBQ=;
b=nTSoKMDnD7EUpZiexm6W+Z/60UsKSxrFT1R7bnSPun7lNRb1wiXOcbvipTE4MWMiWC
5ZdP8LLEKPAygA1qPsA77NL2DL6ZcMY8mJdtynLCuF7CVzXg+NjD7ds2JhWC6jG0Crer
HBOArQukkdgh7FwiqM/DvTsgkHE7Nvri5wmhXIABJzOhGPxVFu9GhHoqqkbC1xzLtOVd
ndOuWNPzrTdWLELyK3Q3VkIo82KwX1Z/JY9JOhc7sJg58N2h/6/n+Qj4/cF8pMtgGJPU
poYHcQJCxNX+f0rDHnws5Vju0qdXzSbdZAl9TUo2yv8upxkY8t8AYYE8VhfLeeavrr44
jmzg==
X-Gm-Message-State: AOAM531q/A9f9NI2rGeCpB2ZhRhipXlRkE9qaSDNmSOP89ob0Y7LSgZg
z7V+ZoIP5uOxOkPhKHIldcacAUFTZWiquDU6QaVoxact51a33Q==
X-Google-Smtp-Source: ABdhPJw6e/9tD9Z0h7wKNsaWP5/T7VO5OO5cvzXH/x6I0HoO+6sM/hfgdjk1xiPbbkccDJxs7E0DdPHLST5wTsPFmQA=
X-Received: by 2002:a05:6a00:198f:b0:50d:bf61:3de9 with SMTP id
d15-20020a056a00198f00b0050dbf613de9mr4606927pfl.16.1651858278124; Fri, 06
May 2022 10:31:18 -0700 (PDT)
In-Reply-To: <CAMA-GnV5+Z-Q7vo+G2x32ytjiVsuCLGxR2NX=BAQPrWGhOHH4Q@mail.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: <CAD+b3HgW6u9+PN--k8CYeWF=ZNg6GX+Tu6hHy_qh9G6y3u9EMQ@mail.gmail.com>
X-Mailman-Original-References: <CAMA-GnV5+Z-Q7vo+G2x32ytjiVsuCLGxR2NX=BAQPrWGhOHH4Q@mail.gmail.com>
 by: Sam Ezeh - Fri, 6 May 2022 17:31 UTC

Perhaps these source references are useful:

Python/ceval.c (_PyEval_EvalFrameDefault)
https://github.com/python/cpython/blob/main/Python/ceval.c#L3754-L3768
Objects/object.c (do_richcompare)
https://github.com/python/cpython/blob/42fee931d055a3ef8ed31abe44603b9b2856e04d/Objects/object.c#L661-L713

Kind regards,
Sam Ezeh

On Fri, 6 May 2022 at 18:12, Jonathan Kaczynski
<jonathan.kaczynski@guildeducation.com> wrote:
>
> Hi,
>
> I was recently trying to explain how python equality works and ran into a
> gap in my knowledge. I haven't found any good pages going beneath a surface
> level explanation of python equality comparison.
>
> I'll post my investigations below. What I think I'm looking for is where in
> the source code (https://github.com/python/cpython) does the equality
> comparison occur. I have an idea but wanted to ask first.
>
>
> Using the dis module, we see the comparison operator is a single bytecode,
> which is expected.
>
> ❯ docker run -it --rm ubuntu:jammy
> root@919d94c98191:/# apt-get update
> root@919d94c98191:/# apt-get --yes install python3
> root@919d94c98191:/# cat >play.py <<EOF
> import dis
> import uuid
>
> def test():
> x = uuid.uuid4()
> y = str(x)
> x == y
> return
>
> dis.dis(test)
> EOF
> root@f33b02fef026:/# python3 play.py
> ... snip ...
> 7 16 LOAD_FAST 0 (x)
> 18 LOAD_FAST 1 (y)
> 20 COMPARE_OP 2 (==)
> 22 POP_TOP
> ... snip ...
>
>
> Stepping through the code with gdb, we see it jump from the compare
> operator to the dunder-eq method on the UUID object. What I want to be able
> to do is explain the in-between steps. Also, if you change `x == y` to `y
> == x`, you still see the same behavior, which I assume has to do with
> dunder-eq being defined on the UUID class and thus given priority.
>
> ❯ docker run -it --rm ubuntu:jammy
> root@919d94c98191:/# apt-get update
> root@919d94c98191:/# apt-get --yes install dpkg-source-gitarchive
> root@919d94c98191:/# sed -i 's/^# deb-src/deb-src/' /etc/apt/sources.list
> root@919d94c98191:/# apt-get update
> root@919d94c98191:/# apt-get --yes install gdb python3.10-dbg
> root@919d94c98191:/# apt-get source python3.10-dbg
> root@919d94c98191:/# cat >play.py <<EOF
> import uuid
> x = uuid.uuid4()
> y = str(x)
> breakpoint()
> x == y
> EOF
> root@919d94c98191:/# gdb python3.10-dbg
> (gdb) dir python3.10-3.10.4/Python
> (gdb) run play.py
> Starting program: /usr/bin/python3.10-dbg play.py
>
> warning: Error disabling address space randomization: Operation not
> permitted
> [Thread debugging using libthread_db enabled]
> Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1"..
> > //play.py(5)<module>()
> -> x == y
> (Pdb) s
> --Call--
> > /usr/lib/python3.10/uuid.py(239)__eq__()
> -> def __eq__(self, other):
>
>
> Thank you,
> Jonathan
> --
> https://mail.python.org/mailman/listinfo/python-list

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor