Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"If you are afraid of loneliness, don't marry." -- Chekhov


devel / comp.lang.python / In code, list.clear doesn't throw error - it's just ignored

SubjectAuthor
* In code, list.clear doesn't throw error - it's just ignoredDFS
+* Re: In code, list.clear doesn't throw error - it's just ignoredJon Ribbens
|+* Re: In code, list.clear doesn't throw error - it's just ignoredDFS
||+* Re: In code, list.clear doesn't throw error - it's just ignoredJon Ribbens
|||+* Re: In code, list.clear doesn't throw error - it's just ignoredGreg Ewing
||||+- Re: In code, list.clear doesn't throw error - it's just ignoredJon Ribbens
||||+* Re: In code, list.clear doesn't throw error - it's just ignoredMRAB
|||||`* Re: In code, list.clear doesn't throw error - it's just ignoredGreg Ewing
||||| `- Re: In code, list.clear doesn't throw error - it's just ignoredChris Angelico
||||+- Re: In code, list.clear doesn't throw error - it's just ignoredChris Angelico
||||`- Re: In code, list.clear doesn't throw error - it's just ignoredKarsten Hilbert
|||`- Re: In code, list.clear doesn't throw error - it's just ignoredStefan Ram
||+* Re: In code, list.clear doesn't throw error - it's just ignoredChris Angelico
|||`* Re: In code, list.clear doesn't throw error - it's just ignoredDFS
||| +* Re: In code, list.clear doesn't throw error - it's just ignoredMichael Speer
||| |+- Re: In code, list.clear doesn't throw error - it's just ignoredStefan Ram
||| |`- Re: In code, list.clear doesn't throw error - it's just ignoredChris Angelico
||| +- Re: In code, list.clear doesn't throw error - it's just ignoredRoel Schroeven
||| `* Re: In code, list.clear doesn't throw error - it's just ignoredCameron Simpson
|||  `* Re: In code, list.clear doesn't throw error - it's just ignoredDennis Lee Bieber
|||   +- Re: In code, list.clear doesn't throw error - it's just ignoredCameron Simpson
|||   `- RE: In code, list.clear doesn't throw error - it's just ignored<avi.e.gross
||`- Re: In code, list.clear doesn't throw error - it's just ignoreddn
|+* Re: In code, list.clear doesn't throw error - it's just ignoredStefan Ram
||`- Re: In code, list.clear doesn't throw error - it's just ignoredStefan Ram
|+* Re: In code, list.clear doesn't throw error - it's just ignoredStefan Ram
||+- Re: In code, list.clear doesn't throw error - it's just ignoredStefan Ram
||`- Re: In code, list.clear doesn't throw error - it's just ignoredJon Ribbens
|`* Re: In code, list.clear doesn't throw error - it's just ignoredStefan Ram
| `- Re: In code, list.clear doesn't throw error - it's just ignoredChris Angelico
+- Re: In code, list.clear doesn't throw error - it's just ignoredWeatherby,Gerard
+- Re: In code, list.clear doesn't throw error - it's just ignoredGilmeh Serda
`- Re: In code, list.clear doesn't throw error - it's just ignoredDan Stromberg

Pages:12
In code, list.clear doesn't throw error - it's just ignored

<akdcL.10609$Sb52.676@fx45.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx45.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.13.1
Newsgroups: comp.lang.python
Content-Language: en-US
From: nos...@dfs.com (DFS)
Subject: In code, list.clear doesn't throw error - it's just ignored
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 27
Message-ID: <akdcL.10609$Sb52.676@fx45.iad>
X-Complaints-To: abuse@blocknews.net
NNTP-Posting-Date: Sun, 13 Nov 2022 21:28:38 UTC
Organization: blocknews - www.blocknews.net
Date: Sun, 13 Nov 2022 16:28:39 -0500
X-Received-Bytes: 1086
 by: DFS - Sun, 13 Nov 2022 21:28 UTC

In code, list.clear is just ignored.
At the terminal, list.clear shows
<built-in method clear of list object at 0x000001C9CFEC4240>

in code:
x = [1,2,3]
x.clear
print(len(x))
3

at terminal:
x = [1,2,3]
x.clear
<built-in method clear of list object at 0x000001C9CFEC4240>
print(len(x))
3

Caused me an hour of frustration before I noticed list.clear() was what
I needed.

x = [1,2,3]
x.clear()
print(len(x))
0

Re: In code, list.clear doesn't throw error - it's just ignored

<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: jon+use...@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Sun, 13 Nov 2022 22:20:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
References: <akdcL.10609$Sb52.676@fx45.iad>
Injection-Date: Sun, 13 Nov 2022 22:20:23 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="6a67a17c6b5bdcb2dcf0d42b79c762d1";
logging-data="1629132"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+I/Nd2KMG6ktZ/zRlWjZQ+pQLax1UcY9U="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:D1J7uC7fWW74VCB8TkW6ZBnwI4s=
 by: Jon Ribbens - Sun, 13 Nov 2022 22:20 UTC

On 2022-11-13, DFS <nospam@dfs.com> wrote:
> In code, list.clear is just ignored.
> At the terminal, list.clear shows
><built-in method clear of list object at 0x000001C9CFEC4240>
>
>
> in code:
> x = [1,2,3]
> x.clear
> print(len(x))
> 3
>
> at terminal:
> x = [1,2,3]
> x.clear
><built-in method clear of list object at 0x000001C9CFEC4240>
> print(len(x))
> 3
>
>
> Caused me an hour of frustration before I noticed list.clear() was what
> I needed.
>
> x = [1,2,3]
> x.clear()
> print(len(x))
> 0

If you want to catch this sort of mistake automatically then you need
a linter such as pylint:

$ cat test.py
"""Create an array and print its length"""

array = [1, 2, 3]
array.clear
print(len(array))
$ pylint -s n test.py
************* Module test
test.py:4:0: W0104: Statement seems to have no effect (pointless-statement)

Re: In code, list.clear doesn't throw error - it's just ignored

<zRecL.17115$Z3L9.382@fx41.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx41.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.13.1
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Content-Language: en-US
Newsgroups: comp.lang.python
References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
From: nos...@dfs.com (DFS)
In-Reply-To: <slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 57
Message-ID: <zRecL.17115$Z3L9.382@fx41.iad>
X-Complaints-To: abuse@blocknews.net
NNTP-Posting-Date: Sun, 13 Nov 2022 23:12:31 UTC
Organization: blocknews - www.blocknews.net
Date: Sun, 13 Nov 2022 18:12:33 -0500
X-Received-Bytes: 2059
 by: DFS - Sun, 13 Nov 2022 23:12 UTC

On 11/13/2022 5:20 PM, Jon Ribbens wrote:
> On 2022-11-13, DFS <nospam@dfs.com> wrote:
>> In code, list.clear is just ignored.
>> At the terminal, list.clear shows
>> <built-in method clear of list object at 0x000001C9CFEC4240>
>>
>>
>> in code:
>> x = [1,2,3]
>> x.clear
>> print(len(x))
>> 3
>>
>> at terminal:
>> x = [1,2,3]
>> x.clear
>> <built-in method clear of list object at 0x000001C9CFEC4240>
>> print(len(x))
>> 3
>>
>>
>> Caused me an hour of frustration before I noticed list.clear() was what
>> I needed.
>>
>> x = [1,2,3]
>> x.clear()
>> print(len(x))
>> 0
>
> If you want to catch this sort of mistake automatically then you need
> a linter such as pylint:
>
> $ cat test.py
> """Create an array and print its length"""
>
> array = [1, 2, 3]
> array.clear
> print(len(array))
> $ pylint -s n test.py
> ************* Module test
> test.py:4:0: W0104: Statement seems to have no effect (pointless-statement)

Thanks, I should use linters more often.

But why is it allowed in the first place?

I stared at list.clear and surrounding code a dozen times and said
"Looks right! Why isn't it clearing the list?!?!"

2 parens later and I'm golden!

Re: In code, list.clear doesn't throw error - it's just ignored

<slrntn333b.4623.jon+usenet@raven.unequivocal.eu>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: jon+use...@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Mon, 14 Nov 2022 00:31:39 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <slrntn333b.4623.jon+usenet@raven.unequivocal.eu>
References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
Injection-Date: Mon, 14 Nov 2022 00:31:39 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="76996512d30d55fb05ea8fc42ec86161";
logging-data="1650668"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+42+t0Lg3QvYuufDwbtvqJUjAAOxwcilU="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:RBADmu/H9w4ZkFr6yVQphfh1LWM=
 by: Jon Ribbens - Mon, 14 Nov 2022 00:31 UTC

On 2022-11-13, DFS <nospam@dfs.com> wrote:
> On 11/13/2022 5:20 PM, Jon Ribbens wrote:
>> On 2022-11-13, DFS <nospam@dfs.com> wrote:
>>> In code, list.clear is just ignored.
>>> At the terminal, list.clear shows
>>> <built-in method clear of list object at 0x000001C9CFEC4240>
>>>
>>>
>>> in code:
>>> x = [1,2,3]
>>> x.clear
>>> print(len(x))
>>> 3
>>>
>>> at terminal:
>>> x = [1,2,3]
>>> x.clear
>>> <built-in method clear of list object at 0x000001C9CFEC4240>
>>> print(len(x))
>>> 3
>>>
>>>
>>> Caused me an hour of frustration before I noticed list.clear() was what
>>> I needed.
>>>
>>> x = [1,2,3]
>>> x.clear()
>>> print(len(x))
>>> 0
>>
>> If you want to catch this sort of mistake automatically then you need
>> a linter such as pylint:
>>
>> $ cat test.py
>> """Create an array and print its length"""
>>
>> array = [1, 2, 3]
>> array.clear
>> print(len(array))
>> $ pylint -s n test.py
>> ************* Module test
>> test.py:4:0: W0104: Statement seems to have no effect (pointless-statement)
>
>
> Thanks, I should use linters more often.
>
> But why is it allowed in the first place?

Because it's an expression, and you're allowed to execute expressions.

Re: In code, list.clear doesn't throw error - it's just ignored

<jtdi03Fi4kqU1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!news.mb-net.net!open-news-network.org!news.mind.de!bolzen.all.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: greg.ew...@canterbury.ac.nz (Greg Ewing)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Mon, 14 Nov 2022 13:55:28 +1300
Lines: 12
Message-ID: <jtdi03Fi4kqU1@mid.individual.net>
References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<slrntn333b.4623.jon+usenet@raven.unequivocal.eu>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net JjvNCTCxNn8QkDvscUaPWQR0nXGDwpLR3cunKWDEygzSM7CP+S
Cancel-Lock: sha1:rgaAVX4WSXoble9wpofyLSCv5q8=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Content-Language: en-US
In-Reply-To: <slrntn333b.4623.jon+usenet@raven.unequivocal.eu>
 by: Greg Ewing - Mon, 14 Nov 2022 00:55 UTC

On 14/11/22 1:31 pm, Jon Ribbens wrote:
> On 2022-11-13, DFS <nospam@dfs.com> wrote:
>> But why is it allowed in the first place?
>
> Because it's an expression, and you're allowed to execute expressions.

To put it a bit more clearly, you're allowed to evaluate
an expression and ignore the result.

--
Greg

Re: In code, list.clear doesn't throw error - it's just ignored

<slrntn361l.4623.jon+usenet@raven.unequivocal.eu>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: jon+use...@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Mon, 14 Nov 2022 01:21:57 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <slrntn361l.4623.jon+usenet@raven.unequivocal.eu>
References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<slrntn333b.4623.jon+usenet@raven.unequivocal.eu>
<jtdi03Fi4kqU1@mid.individual.net>
Injection-Date: Mon, 14 Nov 2022 01:21:57 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="76996512d30d55fb05ea8fc42ec86161";
logging-data="1663397"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Ik4pG89X2M7vGL7hSdQg9nAtJZwcwaCw="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:eJLpVGRpAMLSEJlUQMBzPci+Ccs=
 by: Jon Ribbens - Mon, 14 Nov 2022 01:21 UTC

On 2022-11-14, Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
> On 14/11/22 1:31 pm, Jon Ribbens wrote:
>> On 2022-11-13, DFS <nospam@dfs.com> wrote:
>>> But why is it allowed in the first place?
>>
>> Because it's an expression, and you're allowed to execute expressions.
>
> To put it a bit more clearly, you're allowed to evaluate
> an expression and ignore the result.

.... because it may have side effects, and it's not possible to determine
whether it will or not in advance.

Re: In code, list.clear doesn't throw error - it's just ignored

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!lilly.ping.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Mon, 14 Nov 2022 13:11:11 +1100
Lines: 74
Message-ID: <mailman.966.1668391885.20444.python-list@python.org>
References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<CAPTjJmqJO5pyYjM_A-eGLyVRdn7B1d3B76mQP0TkEYHkGKCqsA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de g987XQ9bNQ82xzR/as36NAHjoBFvkjR9ZBCzR8ApYxeg==
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=NYsIQylv;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.018
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'this:': 0.03; '2022':
0.05; 'subject:error': 0.07; 'problem.': 0.15; '(especially':
0.16; 'cat': 0.16; 'chrisa': 0.16; 'from:addr:rosuav': 0.16;
'from:name:chris angelico': 0.16; 'frustration': 0.16; 'ignored.':
0.16; 'place?': 0.16; 'pylint': 0.16; 'script.': 0.16;
'subject:code': 0.16; 'wrote:': 0.16; 'pm,': 0.19; 'to:addr
:python-list': 0.20; 'code': 0.23; 'seems': 0.26; "isn't": 0.27;
'>>>': 0.28; 'code,': 0.31; 'effect': 0.31; 'module': 0.31;
'message-id:@mail.gmail.com': 0.32; 'but': 0.32; "i'm": 0.33;
'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'built': 0.36; 'mon,': 0.36;
'thanks,': 0.36; 'those': 0.36; 'received:209.85': 0.37;
'received:209': 0.39; 'two': 0.39; 'received:209.85.208': 0.39;
'use': 0.39; 'want': 0.40; 'should': 0.40; 'your': 0.64; 'shows':
0.67; 'surrounding': 0.69; 'times': 0.69; 'them,': 0.70; 'skip:*
10': 0.71; 'catch': 0.84; 'dozen': 0.84; 'jon': 0.84; 'caused':
0.86
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=v40pLeaVPyhGlWUv2wE/OflqLIKM9HG+jR6RGJwCSZE=;
b=NYsIQylvgktlVXw4z39/6cliCSIBAau5vSu3rrfa6yPylFdYNHp5eDbiM2Cx7a5Psf
60xRCWMBMrn1r0FOu7Jpft0q8RatlRKRsk9ZpLcgdnP474NmwYH1QKn4ACUTr1ZOvB6/
s1FxeFEhS1YzDOQavzSkCERl/x/BD45cbSstsyTJZV6g3idRBv2p7f4E2bVVTeAxek8H
J/PKmu+l1Kn9Fti+jpn/vYzxDCoj60TUPXyOyz1FoH8hJSinLb3eLMf3RCTdphO4q33n
jG+/a1vW/Wk3sztw9B6vgvm28CSaESH0w50UnSSsrHXNtnyt2UxjsRXAFhdT8ONoELYV
vKcQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
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=v40pLeaVPyhGlWUv2wE/OflqLIKM9HG+jR6RGJwCSZE=;
b=BHn30BJgHbqPkNYzxW0O3BM+amEAjDP34FpnCF3k3oibPq8s3+F8hxm+CsrVGMx4hb
p8VX7FdY5ctov3YDIt8TInqY+bvvmDRey8tYX2912gJbc5bxy1/7kFI9LNReBpYyqnaf
l7tqDQOhcfH6JE/lPJH1bVOmhC/DD4MTI+zXc1JnzaTCbnUJHCWrpnjv7ONHHTAB8v4M
JqrTiwtib9CbX58+Xd063R6fG3nKL8hvU+goHaA5SQlZpTBTYz0QqeHuTo/Qy7Qnd696
ryA+CpjY6/7gxJQIpf5mbkCErisO4Iv+XwTDiUvEku+bo8u3kl9vx7LadmGxWqajvlSt
0pOw==
X-Gm-Message-State: ANoB5plNOuxJ+hAGXuUVbYupqMVhOxvb/IKWDEXCnaYZwvTmIkbGYPWc
FyLiOml+uyeeaaudjNNBbuO8YB7ulTcfADdAbjlyf/4m
X-Google-Smtp-Source: AA0mqf7jAO57Ju5+zzHsJqCygywh8iqPJVAn0Ii/D2tPE5lVbwzoKfIAeFQB5Ud1HfWQofBT9+5h+G2jL4BEpiHAQAE=
X-Received: by 2002:aa7:d356:0:b0:461:ac48:a5ec with SMTP id
m22-20020aa7d356000000b00461ac48a5ecmr9644003edr.193.1668391882646; Sun, 13
Nov 2022 18:11:22 -0800 (PST)
In-Reply-To: <zRecL.17115$Z3L9.382@fx41.iad>
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: <CAPTjJmqJO5pyYjM_A-eGLyVRdn7B1d3B76mQP0TkEYHkGKCqsA@mail.gmail.com>
X-Mailman-Original-References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
 by: Chris Angelico - Mon, 14 Nov 2022 02:11 UTC

On Mon, 14 Nov 2022 at 11:53, DFS <nospam@dfs.com> wrote:
>
> On 11/13/2022 5:20 PM, Jon Ribbens wrote:
> > On 2022-11-13, DFS <nospam@dfs.com> wrote:
> >> In code, list.clear is just ignored.
> >> At the terminal, list.clear shows
> >> <built-in method clear of list object at 0x000001C9CFEC4240>
> >>
> >>
> >> in code:
> >> x = [1,2,3]
> >> x.clear
> >> print(len(x))
> >> 3
> >>
> >> at terminal:
> >> x = [1,2,3]
> >> x.clear
> >> <built-in method clear of list object at 0x000001C9CFEC4240>
> >> print(len(x))
> >> 3
> >>
> >>
> >> Caused me an hour of frustration before I noticed list.clear() was what
> >> I needed.
> >>
> >> x = [1,2,3]
> >> x.clear()
> >> print(len(x))
> >> 0
> >
> > If you want to catch this sort of mistake automatically then you need
> > a linter such as pylint:
> >
> > $ cat test.py
> > """Create an array and print its length"""
> >
> > array = [1, 2, 3]
> > array.clear
> > print(len(array))
> > $ pylint -s n test.py
> > ************* Module test
> > test.py:4:0: W0104: Statement seems to have no effect (pointless-statement)
>
>
> Thanks, I should use linters more often.
>
> But why is it allowed in the first place?
>
> I stared at list.clear and surrounding code a dozen times and said
> "Looks right! Why isn't it clearing the list?!?!"
>
> 2 parens later and I'm golden!
>

No part of it is invalid, so nothing causes a problem. For instance,
you can write this:

>>> 1

And you can write this:

>>> 1 + 2

And you can write this:

>>> print(1 + 2)

But only one of those is useful in a script. Should the other two be
errors? No. But linters WILL usually catch them, so if you have a good
linter (especially built into your editor), you can notice these
things.

ChrisA

Re: In code, list.clear doesn't throw error - it's just ignored

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: pyt...@mrabarnett.plus.com (MRAB)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Mon, 14 Nov 2022 02:13:34 +0000
Lines: 12
Message-ID: <mailman.967.1668392205.20444.python-list@python.org>
References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<slrntn333b.4623.jon+usenet@raven.unequivocal.eu>
<jtdi03Fi4kqU1@mid.individual.net>
<0b97e354-49a3-f7bb-a3bb-3f2f6024ae68@mrabarnett.plus.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de +cLATsOPpzbXb8Pyd2LMKgH5MdCRn+pBh32loTP0bYMw==
Return-Path: <python@mrabarnett.plus.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=plus.com header.i=@plus.com header.b=WZqoR/Jk;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:error': 0.07;
'expression': 0.09; 'from:addr:python': 0.09;
'received:192.168.1.64': 0.09; 'call,': 0.16; 'expressions.':
0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab':
0.16; 'greg': 0.16; 'message-id:@mrabarnett.plus.com': 0.16;
'place?': 0.16; 'received:plus.net': 0.16; 'subject:code': 0.16;
'wrote:': 0.16; 'probably': 0.17; 'pm,': 0.19; 'to:addr:python-
list': 0.20; 'bit': 0.27; '>>>': 0.28; 'header:User-Agent:1':
0.30; 'received:192.168.1': 0.32; 'but': 0.32; 'header:In-Reply-
To:1': 0.34; "it's": 0.37; 'received:192.168': 0.37; 'put': 0.38;
'received:212': 0.62; 'ignore': 0.71; 'jon': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plus.com; s=042019;
t=1668392017; bh=VkodUuXMS8XSlV8W6hG6hkqzYuis0xu1lK769buTeEw=;
h=Date:Subject:To:References:From:In-Reply-To;
b=WZqoR/Jkq/vqaf2UQQcMP9Ka8NtENxZmp7XuPkYJvq5ydASc+IXjkG0RmrvjawjjA
AVQPaO9JnJIhW4GR7KjM6v1tXlQwV6jW5Rl204BNeatfEYUr6MOPRW263tysZmmlN1
zPMrscXvhFQr/TVC6HTL28L9kvGrxdJkLK5rZNpZUwVQLr7vAcZQv2Un1NnEJFBmPh
6EeBb2oHweW3Imqf7CpIEd5R5gVcTu2S+p1StjKjmOdY+lkapslNYboiF6EWbnBVue
xvfQ7I68WbA0trFXA5clYSG9uvYX5lI39vZNkwL4OusbyQcQMTyL/qRScZ22qeKBcm
WOatFlFtU9DNQ==
X-Clacks-Overhead: "GNU Terry Pratchett"
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.4 cv=R88QpPdX c=1 sm=1 tr=0 ts=6371a451
a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=IkcTkHD0fZMA:10 a=oDhjSesRAAAA:8 a=nmZfdXwwhBHe2wfnNaMA:9 a=QEXdDO2ut3YA:10
a=BrBYco0LsekBUjFlMg6z:22
X-AUTH: mrabarnett@:2500
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Content-Language: en-GB
In-Reply-To: <jtdi03Fi4kqU1@mid.individual.net>
X-CMAE-Envelope: MS4xfFB4kZpYJgmBNWrwGaJI+ceHs4c5uJmNhYSzPAF4M8ob7jEJP/ivfTwAgXMs0ztfrxImb7Fp1/dKXbPsdv/ihpGvpvCEOLpyZl9fMnKI7E9UoykMWCTJ
+YENPb6KylWgi47xUPr25aV2/cattxBTEat8xAdsYORvY0ams4/Inixp+p8qTPrQ4Q7pDcY/DGFGEFXd9InhgsEFyt9jyEa0wt8=
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: <0b97e354-49a3-f7bb-a3bb-3f2f6024ae68@mrabarnett.plus.com>
X-Mailman-Original-References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<slrntn333b.4623.jon+usenet@raven.unequivocal.eu>
<jtdi03Fi4kqU1@mid.individual.net>
 by: MRAB - Mon, 14 Nov 2022 02:13 UTC

On 2022-11-14 00:55, Greg Ewing wrote:
> On 14/11/22 1:31 pm, Jon Ribbens wrote:
>> On 2022-11-13, DFS <nospam@dfs.com> wrote:
>>> But why is it allowed in the first place?
>>
>> Because it's an expression, and you're allowed to execute expressions.
>
> To put it a bit more clearly, you're allowed to evaluate
> an expression and ignore the result.
>
But if it's an expression where it's expecting a statement and it's not
a call, then it's probably a bug.

Re: In code, list.clear doesn't throw error - it's just ignored

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!lilly.ping.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Mon, 14 Nov 2022 13:22:31 +1100
Lines: 28
Message-ID: <mailman.968.1668392566.20444.python-list@python.org>
References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<slrntn333b.4623.jon+usenet@raven.unequivocal.eu>
<jtdi03Fi4kqU1@mid.individual.net>
<0b97e354-49a3-f7bb-a3bb-3f2f6024ae68@mrabarnett.plus.com>
<CAPTjJmpL=Ktp1avs3QzkDJzLTBTYMRpvfOL2Vju703_kxP7uKg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de KQfTODbN5cgZrPTbFDYCwA66xfNHo/hzUwuBK9j1zDOQ==
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=TVqJHuTO;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.006
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '2022': 0.05;
'subject:error': 0.07; 'expression': 0.09; 'call,': 0.16;
'chrisa': 0.16; 'conditional': 0.16; 'expressions.': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'greg': 0.16; 'place?': 0.16; 'received:209.85.218': 0.16;
'subject:code': 0.16; 'useful.': 0.16; 'wrote:': 0.16; 'probably':
0.17; 'pm,': 0.19; 'to:addr:python-list': 0.20; 'language': 0.21;
"i'd": 0.24; 'bit': 0.27; '>>>': 0.28; 'message-
id:@mail.gmail.com': 0.32; 'but': 0.32; 'header:In-Reply-To:1':
0.34; 'received:google.com': 0.34; 'definitely': 0.35;
'from:addr:gmail.com': 0.35; 'mon,': 0.36; "it's": 0.37;
'received:209.85': 0.37; 'put': 0.38; 'received:209': 0.39;
'both': 0.40; 'likely': 0.61; 'skip:o 10': 0.61; 'spam': 0.65;
'ignore': 0.71; 'itself.': 0.84; 'jon': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=kcM3g+apYrtVLoh/cWdl4EGSUZY/L5GOhUKW1K4MbVg=;
b=TVqJHuTOQtART3WanLSDpTxEsU43utttmK79R8YiPfQEi5ih9jkOlD1+haSNYRrlkn
lmB8mwOpGiMOcrC70QVLyDcWIMYOXRX/XqJNVZEwbRd9u9oxLbHyWnOcrJeIfdRDX0nu
btxm6zh6jHC0dx+KKvcD9r0j3hVwRZvYPBBbFlXa9k2T9eq4GDsK7eUu3L40lePPDzDW
ZfRa5i/0lDycOy91ffeXkNAKsZIAUJdi5y2dzgTQKDCTIXwDRkJNYH4wbsiOyI2RbR5J
WtD9ZS6tJz/ZZxAQ3c+IxWQciMTPEAJJ/3UA4U/N5O2Ip8NqwRQD/aXYzjSbPAm/jt80
n8hA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
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=kcM3g+apYrtVLoh/cWdl4EGSUZY/L5GOhUKW1K4MbVg=;
b=4HNqFVwWwSLhn7awfpXADZiTBnn1ZsTioMuDh4mZ7EckhsC2NIYm8CaTfbZZE14s4T
yRK6YqXiYg4PSgTRjOWsojiSGmB6U7+5NdNY/wS2nEFju0iuLpnyWIlO4O7V9AvvTADx
I/m5PnX9iWuwUbwkPPu6TfD6+G1aS7xDXPtXzb5kEsWt1h1nHc6btcQuT78hQdhLIX4L
0OTVrGsL40jGeN6qTP9pU4plKUPs3WinPLG23Q9tNh++Q7C/IIjqd/9bSYBOup7wwQMH
Un2IHclpEU+RvXPB05N+jmjy0iRbQS3O7hqR4kzaXopAHT3IpZ0otecJJySgaKQy1wH3
Qpuw==
X-Gm-Message-State: ANoB5pmkqT3SeqEFaW6c1XQ5dWG/dk2wjxfqlhW6wGxfczHLW8AkkQXQ
h2zXcy0xeQ8p0tISk6lDcC/KVEJn3VXpxHgJeXJ/9v5z
X-Google-Smtp-Source: AA0mqf6adOGGERmuchCOBfGz9lKsvPms/rLT4nGcl0Mzp4D4zLGMNl0WgosnuKMbTFrDdLs/xCpefDqxy7kVppb0KVs=
X-Received: by 2002:a17:907:9505:b0:7ac:9917:72ed with SMTP id
ew5-20020a170907950500b007ac991772edmr8620429ejc.650.1668392563479; Sun, 13
Nov 2022 18:22:43 -0800 (PST)
In-Reply-To: <0b97e354-49a3-f7bb-a3bb-3f2f6024ae68@mrabarnett.plus.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: <CAPTjJmpL=Ktp1avs3QzkDJzLTBTYMRpvfOL2Vju703_kxP7uKg@mail.gmail.com>
X-Mailman-Original-References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<slrntn333b.4623.jon+usenet@raven.unequivocal.eu>
<jtdi03Fi4kqU1@mid.individual.net>
<0b97e354-49a3-f7bb-a3bb-3f2f6024ae68@mrabarnett.plus.com>
 by: Chris Angelico - Mon, 14 Nov 2022 02:22 UTC

On Mon, 14 Nov 2022 at 13:18, MRAB <python@mrabarnett.plus.com> wrote:
>
> On 2022-11-14 00:55, Greg Ewing wrote:
> > On 14/11/22 1:31 pm, Jon Ribbens wrote:
> >> On 2022-11-13, DFS <nospam@dfs.com> wrote:
> >>> But why is it allowed in the first place?
> >>
> >> Because it's an expression, and you're allowed to execute expressions.
> >
> > To put it a bit more clearly, you're allowed to evaluate
> > an expression and ignore the result.
> >
> But if it's an expression where it's expecting a statement and it's not
> a call, then it's probably a bug.

Maybe, but I'd be dubious of making it that simplistic. For instance,
which of these is more likely to be useless?

spam or ham()
spam() or ham

Syntactically, both of them are 'or' expressions, but one of them is
almost certainly unnecessary, while the other is just an oddly-written
conditional statement and most definitely useful.

In any case, this is the job of linters, NOT the language itself.

ChrisA

Re: In code, list.clear doesn't throw error - it's just ignored

<uwicL.23347$t_J9.22390@fx43.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx43.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.13.1
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Content-Language: en-US
Newsgroups: comp.lang.python
References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<CAPTjJmqJO5pyYjM_A-eGLyVRdn7B1d3B76mQP0TkEYHkGKCqsA@mail.gmail.com>
<mailman.966.1668391885.20444.python-list@python.org>
From: nos...@dfs.com (DFS)
In-Reply-To: <mailman.966.1668391885.20444.python-list@python.org>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 105
Message-ID: <uwicL.23347$t_J9.22390@fx43.iad>
X-Complaints-To: abuse@blocknews.net
NNTP-Posting-Date: Mon, 14 Nov 2022 03:23:06 UTC
Organization: blocknews - www.blocknews.net
Date: Sun, 13 Nov 2022 22:23:09 -0500
X-Received-Bytes: 3366
 by: DFS - Mon, 14 Nov 2022 03:23 UTC

On 11/13/2022 9:11 PM, Chris Angelico wrote:
> On Mon, 14 Nov 2022 at 11:53, DFS <nospam@dfs.com> wrote:
>>
>> On 11/13/2022 5:20 PM, Jon Ribbens wrote:
>>> On 2022-11-13, DFS <nospam@dfs.com> wrote:
>>>> In code, list.clear is just ignored.
>>>> At the terminal, list.clear shows
>>>> <built-in method clear of list object at 0x000001C9CFEC4240>
>>>>
>>>>
>>>> in code:
>>>> x = [1,2,3]
>>>> x.clear
>>>> print(len(x))
>>>> 3
>>>>
>>>> at terminal:
>>>> x = [1,2,3]
>>>> x.clear
>>>> <built-in method clear of list object at 0x000001C9CFEC4240>
>>>> print(len(x))
>>>> 3
>>>>
>>>>
>>>> Caused me an hour of frustration before I noticed list.clear() was what
>>>> I needed.
>>>>
>>>> x = [1,2,3]
>>>> x.clear()
>>>> print(len(x))
>>>> 0
>>>
>>> If you want to catch this sort of mistake automatically then you need
>>> a linter such as pylint:
>>>
>>> $ cat test.py
>>> """Create an array and print its length"""
>>>
>>> array = [1, 2, 3]
>>> array.clear
>>> print(len(array))
>>> $ pylint -s n test.py
>>> ************* Module test
>>> test.py:4:0: W0104: Statement seems to have no effect (pointless-statement)
>>
>>
>> Thanks, I should use linters more often.
>>
>> But why is it allowed in the first place?
>>
>> I stared at list.clear and surrounding code a dozen times and said
>> "Looks right! Why isn't it clearing the list?!?!"
>>
>> 2 parens later and I'm golden!
>>
>
> No part of it is invalid, so nothing causes a problem. For instance,
> you can write this:

If it wastes time like that it's invalid.

This is an easy check for the interpreter to make.

If I submit a suggestion to python-list@python.org will it just show up
here? Or do the actual Python devs intercept it?

>>>> 1
>
> And you can write this:
>
>>>> 1 + 2
>
> And you can write this:
>
>>>> print(1 + 2)
>
> But only one of those is useful in a script. Should the other two be
> errors? No. But linters WILL usually catch them, so if you have a good
> linter (especially built into your editor), you can notice these
> things.

ran pylint against it and got 0.0/10.

--disable=
invalid-name
multiple-statements
bad-indentation
line-too-long
trailing-whitespace
missing-module-docstring
missing-function-docstring
too-many-lines
fixme

and got 8.9/10.

Re: In code, list.clear doesn't throw error - it's just ignored

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.neodome.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: knome...@gmail.com (Michael Speer)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Sun, 13 Nov 2022 23:53:08 -0500
Lines: 162
Message-ID: <mailman.969.1668401602.20444.python-list@python.org>
References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<CAPTjJmqJO5pyYjM_A-eGLyVRdn7B1d3B76mQP0TkEYHkGKCqsA@mail.gmail.com>
<mailman.966.1668391885.20444.python-list@python.org>
<uwicL.23347$t_J9.22390@fx43.iad>
<CABpSurAU-i0PBZoyq+npf6ead+9xt-K60AZEirArLdJwRDJoiQ@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de ece8yv8UEggWvZe/KK9i7gM8JMgttLTlbR+xbRS3J46A==
Return-Path: <knome.net@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=e2kRzBoq;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'this:': 0.03; 'argument':
0.04; '2022': 0.05; 'bunch': 0.05; 'library.': 0.05;
'&gt;&gt;&gt;': 0.07; 'subject:error': 0.07; 'suggestion': 0.07;
'sun,': 0.07; 'tests': 0.07; 'angelico': 0.09; 'cc:addr:python-
list': 0.09; 'expression': 0.09; 'skip:\xc2 20': 0.09; '&gt;':
0.14; 'cc:no real name:2**0': 0.14; 'url:mailman': 0.15;
'problem.': 0.15; '(especially': 0.16; '>>>>': 0.16; 'arbitrary':
0.16; 'be,': 0.16; 'cat': 0.16; 'devs': 0.16; 'effects.': 0.16;
'expressions': 0.16; 'frustration': 0.16; 'ignored.': 0.16;
'inspect': 0.16; 'interpreter': 0.16; 'place?': 0.16; 'pylint':
0.16; 'rerun': 0.16; 'script.': 0.16; 'stuck': 0.16;
'subject:code': 0.16; 'wrote:': 0.16; 'python': 0.16; 'values':
0.17; "can't": 0.17; 'it?': 0.19; 'pm,': 0.19;
'cc:addr:python.org': 0.20; 'input': 0.21; 'written': 0.22; 'ran':
0.22; 'returns': 0.22; 'code': 0.23; "i'd": 0.24; 'url-
ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24': 0.25;
'actual': 0.25; 'url:listinfo': 0.25; 'cc:2**0': 0.25; 'url-
ip:188.166/16': 0.25; 'seems': 0.26; 'object': 0.26; "isn't":
0.27; 'coming': 0.27; 'function': 0.27; '>>>': 0.28; 'chris':
0.28; 'output': 0.28; 'error': 0.29; 'code,': 0.31; 'effect':
0.31; 'module': 0.31; 'url-ip:188/8': 0.31; "doesn't": 0.32;
'13,': 0.32; 'programmers': 0.32; 'message-id:@mail.gmail.com':
0.32; 'but': 0.32; "i'm": 0.33; 'there': 0.33; 'particular': 0.33;
'script': 0.33; 'mean': 0.34; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35; 'built':
0.36; 'functions': 0.36; 'mon,': 0.36; 'thanks,': 0.36; 'people':
0.36; 'those': 0.36; "it's": 0.37; 'received:209.85': 0.37;
'author': 0.37; 'class': 0.37; 'hard': 0.37; '8bit%:14': 0.38;
'received:209': 0.39; 'two': 0.39; 'list': 0.39; 'use': 0.39;
'something': 0.40; 'want': 0.40; 'should': 0.40; 'tell': 0.60;
'method': 0.61; 'skip:0 20': 0.61; 'skip:\xc2 10': 0.62;
'reasonable': 0.62; 'skip:m 20': 0.63; 'skip:b 10': 0.63; 'clear':
0.64; 'accessing': 0.64; 'your': 0.64; 'produce': 0.65; 'look':
0.65; 'decided': 0.67; 'shows': 0.67; 'back': 0.67; 'away': 0.67;
'right': 0.68; 'during': 0.69; 'perfectly': 0.69; 'surrounding':
0.69; 'times': 0.69; 'them,': 0.70; 'you.': 0.71; 'care': 0.71;
'skip:* 10': 0.71; 'easy': 0.74; 'supposed': 0.76; 'returned':
0.81; 'attribute': 0.84; 'catch': 0.84; 'dozen': 0.84; 'inputs':
0.84; 'invalid.': 0.84; 'jon': 0.84; 'want.': 0.84; 'caused': 0.86
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=cc:to:subject:message-id:date:from:in-reply-to:references
:mime-version:from:to:cc:subject:date:message-id:reply-to;
bh=jkbW0CZM1wvI5tcXFjTX54NtL5nnqlLUSqmlrQXS3NE=;
b=e2kRzBoqNR55CQDc6WHXatXW7vRKb9hCfN4E1V+92NRkii8V1m5iju9IhCedc4IHW0
g9BEwkgaaWDQ2j8UewdmsZ5Ltiqliu9JGf64hYMlhOF5fcpKJ3uoFrET2kBQP8gxjKjT
il9Hvkq7L/5eEmixo9V/fazwhyaRpI5ynnY6fV1j0fE53qpgjyw6DJdWzIDqi57mUROI
arlIx1jChpLNH7/rgfViTyyE67BSEeJ3LJlB7BJUjrd7fg8UVIsDA3XLQHX3NLlkDSQ5
246dXIH4TWKK4sroN0Sx0/q8lp/BO+qOw9n6vtP3GGt45C65rJqHGSHQh06ncj8+/PV1
DMXw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=cc: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=jkbW0CZM1wvI5tcXFjTX54NtL5nnqlLUSqmlrQXS3NE=;
b=77fxUzBhmLslbHY4hJxabymXKbPnHOhWTw7IUA8qdAUXzp/00poxwv6BaMpxoCcg4p
lXKGsc9notmbOcq+Uh8gOyMqcBvWDxdAngozXy5STOccKSUvLq19AmxwxpuoHcQ966q2
7HWubAqI73IlEk/cDQ67blsPdxag06sMRTdlycNm7JeSraeOAK8S61Ir1ve7OgTmW9zE
ZqXKnge1ifdzpAokk4lZraCdU7uCNS1h6YxSxE6Ur6qp6hdtnf6fvO2iszWlqcLGyyqR
7DkmT9xsp1mIUZDcZNu/OK/+T96dxHTCUFJfRwWnVmWD9FZsBO4A2SOZ4vOiyANKPO6V
AxnQ==
X-Gm-Message-State: ANoB5pnRDjfeiboAWqYTApnkdZtkPlagzqt/wvS403IDFJLr8DLc4yex
H7U/8T4JeJyoheZlOTgL66RPzZh2NWVqiV4NrCI1FgSh
X-Google-Smtp-Source: AA0mqf562l1uaTDtw4ihWIUJT6eMOj0fQUstt7I2hoW1Bmr+yePdxYNr9q1L0eBLp+FKH7Yvf9tg34PVIQFzZ8atxAQ=
X-Received: by 2002:a05:6512:3a5:b0:4b3:a78b:2e7d with SMTP id
v5-20020a05651203a500b004b3a78b2e7dmr3465640lfp.363.1668401600540; Sun, 13
Nov 2022 20:53:20 -0800 (PST)
In-Reply-To: <uwicL.23347$t_J9.22390@fx43.iad>
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: <CABpSurAU-i0PBZoyq+npf6ead+9xt-K60AZEirArLdJwRDJoiQ@mail.gmail.com>
X-Mailman-Original-References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<CAPTjJmqJO5pyYjM_A-eGLyVRdn7B1d3B76mQP0TkEYHkGKCqsA@mail.gmail.com>
<mailman.966.1668391885.20444.python-list@python.org>
<uwicL.23347$t_J9.22390@fx43.iad>
 by: Michael Speer - Mon, 14 Nov 2022 04:53 UTC

Python doesn't care what an expression returns.

You've written an expression that returns the value of the 'clear' function
that is bound to that particular list.

The interpreter doesn't know or care if accessing that 'clear' attribute on
the class returns a function or for some reason triggers a bunch of side
effects that the author decided they wanted to use __getattr__ to trigger.

'list.clear' might be a perfectly reasonable expression in some library.
I'd rather it not be, but hey, there are millions of python programmers
making all kinds of code out there

arbitrary expressions can have arbitrary effects. just because a value
isn't assigned, returned or used as an argument to a function doesn't mean
it isn't doing anything.

you might then want python to inspect the result of the function, but how
can python know if the author isn't purposely ignoring the return value of
the expression?

people can call functions that return values for only their side effects.

if you can't tell by the form of the expression or the value it returns,
what is the linter supposed to look for?

what is the interpreter supposed to look for?

if you want to avoid accidentally failing to clear a list during a
function, you should write tests that check that various inputs to the
function produce the expected outputs.

'unit tests' are a good place to make sure that code is acting as you want
it to

for one-off scripts, you should always make the thing dry-run or convert
from an input to an output (rather than in-place) so you can rerun them a
few times and make sure they're doing what you want.

sometimes making sure things are right is just on you.

there will always be the occasional silly error in a script that is hard to
see until you step away for a moment.

stepping away and coming back is a pretty good thing to do if you're stuck
on something that feels impossible.

On Sun, Nov 13, 2022 at 10:33 PM DFS <nospam@dfs.com> wrote:

> On 11/13/2022 9:11 PM, Chris Angelico wrote:
> > On Mon, 14 Nov 2022 at 11:53, DFS <nospam@dfs.com> wrote:
> >>
> >> On 11/13/2022 5:20 PM, Jon Ribbens wrote:
> >>> On 2022-11-13, DFS <nospam@dfs.com> wrote:
> >>>> In code, list.clear is just ignored.
> >>>> At the terminal, list.clear shows
> >>>> <built-in method clear of list object at 0x000001C9CFEC4240>
> >>>>
> >>>>
> >>>> in code:
> >>>> x = [1,2,3]
> >>>> x.clear
> >>>> print(len(x))
> >>>> 3
> >>>>
> >>>> at terminal:
> >>>> x = [1,2,3]
> >>>> x.clear
> >>>> <built-in method clear of list object at 0x000001C9CFEC4240>
> >>>> print(len(x))
> >>>> 3
> >>>>
> >>>>
> >>>> Caused me an hour of frustration before I noticed list.clear() was
> what
> >>>> I needed.
> >>>>
> >>>> x = [1,2,3]
> >>>> x.clear()
> >>>> print(len(x))
> >>>> 0
> >>>
> >>> If you want to catch this sort of mistake automatically then you need
> >>> a linter such as pylint:
> >>>
> >>> $ cat test.py
> >>> """Create an array and print its length"""
> >>>
> >>> array = [1, 2, 3]
> >>> array.clear
> >>> print(len(array))
> >>> $ pylint -s n test.py
> >>> ************* Module test
> >>> test.py:4:0: W0104: Statement seems to have no effect
> (pointless-statement)
> >>
> >>
> >> Thanks, I should use linters more often.
> >>
> >> But why is it allowed in the first place?
> >>
> >> I stared at list.clear and surrounding code a dozen times and said
> >> "Looks right! Why isn't it clearing the list?!?!"
> >>
> >> 2 parens later and I'm golden!
> >>
> >
> > No part of it is invalid, so nothing causes a problem. For instance,
> > you can write this:
>
>
> If it wastes time like that it's invalid.
>
> This is an easy check for the interpreter to make.
>
> If I submit a suggestion to python-list@python.org will it just show up
> here? Or do the actual Python devs intercept it?
>
>
>
>
>
>
> >>>> 1
> >
> > And you can write this:
> >
> >>>> 1 + 2
> >
> > And you can write this:
> >
> >>>> print(1 + 2)
> >
> > But only one of those is useful in a script. Should the other two be
> > errors? No. But linters WILL usually catch them, so if you have a good
> > linter (especially built into your editor), you can notice these
> > things.
>
>
> ran pylint against it and got 0.0/10.
>
>
> --disable=
> invalid-name
> multiple-statements
> bad-indentation
> line-too-long
> trailing-whitespace
> missing-module-docstring
> missing-function-docstring
> too-many-lines
> fixme
>
>
> and got 8.9/10.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Re: In code, list.clear doesn't throw error - it's just ignored

<jte11qFk821U1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!news.szaf.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: greg.ew...@canterbury.ac.nz (Greg Ewing)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Mon, 14 Nov 2022 18:12:23 +1300
Lines: 12
Message-ID: <jte11qFk821U1@mid.individual.net>
References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<slrntn333b.4623.jon+usenet@raven.unequivocal.eu>
<jtdi03Fi4kqU1@mid.individual.net>
<0b97e354-49a3-f7bb-a3bb-3f2f6024ae68@mrabarnett.plus.com>
<mailman.967.1668392205.20444.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net yV7viZSw7oOXhuJKZBZt2AEoulvt3PCOMtW/bB72jY3QmO4/NS
Cancel-Lock: sha1:wwymffJ3b9zk/xncUCNwAjZ3QDU=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Content-Language: en-US
In-Reply-To: <mailman.967.1668392205.20444.python-list@python.org>
 by: Greg Ewing - Mon, 14 Nov 2022 05:12 UTC

On 14/11/22 3:13 pm, MRAB wrote:
> But if it's an expression where it's expecting a statement and it's not
> a call, then it's probably a bug.

The key word there is "probably". If there's any chance it
could be not a bug, it can't be an error. At most it should
be a warning, and that's what linters are for. I wouldn't
like the core interpreter to be producing a bunch of warnings
for things like this.

--
Greg

Re: In code, list.clear doesn't throw error - it's just ignored

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Mon, 14 Nov 2022 18:08:38 +1100
Lines: 33
Message-ID: <mailman.970.1668409731.20444.python-list@python.org>
References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<slrntn333b.4623.jon+usenet@raven.unequivocal.eu>
<jtdi03Fi4kqU1@mid.individual.net>
<0b97e354-49a3-f7bb-a3bb-3f2f6024ae68@mrabarnett.plus.com>
<mailman.967.1668392205.20444.python-list@python.org>
<jte11qFk821U1@mid.individual.net>
<CAPTjJmrtRqqO1aoOeHZ9vUcO9sTkYK=dbCCRyGEN5v_eSDdF5A@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de yJI8t3CJlibU4RztPtY9vw4NV9wx6H5hSK+H1Fy2mDaA==
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=BiF5sZv/;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '2022': 0.05; 'bunch':
0.05; 'subject:error': 0.07; 'expression': 0.09; 'bug,': 0.16;
'call,': 0.16; 'chrisa': 0.16; 'cope': 0.16; 'for.': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'greg': 0.16; 'interpreter': 0.16; 'polyglot': 0.16;
'received:209.85.218': 0.16; 'subject:code': 0.16; 'useless':
0.16; 'wrote:': 0.16; 'probably': 0.17; "can't": 0.17; 'name.':
0.19; 'pm,': 0.19; 'to:addr:python-list': 0.20; 'input': 0.21;
'code': 0.23; "wouldn't": 0.32; 'message-id:@mail.gmail.com':
0.32; 'but': 0.32; 'there': 0.33; 'particular': 0.33; 'core':
0.34; 'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'complex': 0.35; 'from:addr:gmail.com': 0.35; 'mon,': 0.36;
'those': 0.36; "it's": 0.37; 'received:209.85': 0.37; 'this.':
0.37; 'way': 0.38; 'could': 0.38; 'received:209': 0.39; 'two':
0.39; 'should': 0.40; "there's": 0.61; 'between': 0.63; 'key':
0.64; 'taught': 0.64; 'chance': 0.71; 'easy': 0.74; 'handles':
0.76
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=qAEJ0w7Qz4wFdr6hnzgyE0sNnvNhabkKpUpTyUkB5tE=;
b=BiF5sZv/USXg1wieASApAPqIetWfRbm9npq3iI8+p6t/RD8st67O+IMPGWPJmoGKHf
ZbXeoN65fpc0rgeZHQmj52TKMY3G2sA/Lgrsx5GyjrHJIhI9csDnDdioVs7OB8TwNE4X
L+GwGi1/huCN6yIactpNrJwCVTdp9MhR+ur0LTf7IHu6I8jpfl5FUCFrOgYGjfEeuzae
YkUByI8EH5k390v1L8F222C/xE2o9s+9nLqwtiqA1JPuwwWdgkkKBvkRZkRyhMA2G+E6
mfyEKSeGhQyVJf2sipZva0QEutV9HdOmaJae/2+1sTKgf4sigV78RhmK22LV/UEPNuNQ
jocw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
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=qAEJ0w7Qz4wFdr6hnzgyE0sNnvNhabkKpUpTyUkB5tE=;
b=TV3N5k/WKcUmjJx3i//Jh2eHMsJpcG2QXC9APtzQrAR0e1v4mfpGkA85DUBE/Sjekw
StRh20MrYazvsvNJOXi/tQm4kv3GsPSoQdO2v+ST7c+h0Y7dl9IG1Jl+0SlIDDjm+P23
/P34K6v55Qhe/IOM+dCcFg68qEW6W51QUqqjLrK1K4N4T8TVH/cttmMWBu8jF65a/vph
IpKNSEGvDFsDUiOn5Y8Nn+A2c3pJmZsRow0PFhBTUvya4/A2Uq0zdU69LbCxSkd7wBxf
/raNZGRgcCcs7NFVRKmPsuTJ+Kni2svvBEkD5Lmygiy6281dU5o6FXKE7Khzth2SM8ob
kidw==
X-Gm-Message-State: ANoB5pmmHEQf/fUdoD280Dg+UB7EvopEfBQd3j5/lIqQ373UzYfcQC4H
9fe1Ge5sWpiuwqkENpHBK6F7u3LvesEhkafezAXWDyjc
X-Google-Smtp-Source: AA0mqf77GJzcflrFpygnnoffkNspBghyfOdlxZTLm9Sj9zhIgHr2ZXQOvKtV7oLotgAp+FrlTsh6VjQcLBN2/PWO6Yk=
X-Received: by 2002:a17:907:c01b:b0:7ad:9891:8757 with SMTP id
ss27-20020a170907c01b00b007ad98918757mr9419228ejc.335.1668409729902; Sun, 13
Nov 2022 23:08:49 -0800 (PST)
In-Reply-To: <jte11qFk821U1@mid.individual.net>
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: <CAPTjJmrtRqqO1aoOeHZ9vUcO9sTkYK=dbCCRyGEN5v_eSDdF5A@mail.gmail.com>
X-Mailman-Original-References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<slrntn333b.4623.jon+usenet@raven.unequivocal.eu>
<jtdi03Fi4kqU1@mid.individual.net>
<0b97e354-49a3-f7bb-a3bb-3f2f6024ae68@mrabarnett.plus.com>
<mailman.967.1668392205.20444.python-list@python.org>
<jte11qFk821U1@mid.individual.net>
 by: Chris Angelico - Mon, 14 Nov 2022 07:08 UTC

On Mon, 14 Nov 2022 at 18:00, Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
>
> On 14/11/22 3:13 pm, MRAB wrote:
> > But if it's an expression where it's expecting a statement and it's not
> > a call, then it's probably a bug.
>
> The key word there is "probably". If there's any chance it
> could be not a bug, it can't be an error. At most it should
> be a warning, and that's what linters are for. I wouldn't
> like the core interpreter to be producing a bunch of warnings
> for things like this.
>

Notably, linters can be taught about more complex idioms, like:

try:
raw_input
except NameError:
raw_input = input

which is an easy way to make polyglot Py2/Py3 code that handles the
presence/absence of a particular name. Or, similarly:

try:
os.sendfile
except AttributeError:
... # cope with sendfile not being available

When os.sendfile exists, it's a completely useless expression. When it
doesn't, it's an error. But the difference between those two is
crucial.

ChrisA

Re: In code, list.clear doesn't throw error - it's just ignored

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonL...@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Mon, 14 Nov 2022 20:25:30 +1300
Organization: DWM
Lines: 137
Message-ID: <mailman.971.1668410742.20444.python-list@python.org>
References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<f367ab58-3cdb-a2e8-546e-11238999654a@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de /0tzAKHtr8/oKYNDcR5kIgO8jmt3KnbiSKm0dyykeo9w==
Return-Path: <PythonList@DancesWithMice.info>
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=danceswithmice.info header.i=@danceswithmice.info
header.b=Tw63GlB9; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.022
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'looks': 0.02; 'generated':
0.03; 'subject:error': 0.07; '=dn': 0.09; 'difficulty': 0.09;
'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
0.09; 'skip:[ 20': 0.09; 'steps': 0.11; 'accordingly': 0.16;
'arguments': 0.16; 'cat': 0.16; 'class"': 0.16; 'fibonacci': 0.16;
'frustration': 0.16; 'ignored.': 0.16; 'machine,': 0.16; 'message-
id:@DancesWithMice.info': 0.16; 'place?': 0.16; 'prime': 0.16;
'pylint': 0.16; 'received:51.254': 0.16; 'received:51.254.211':
0.16; 'received:51.254.211.219': 0.16; 'received:cloud': 0.16;
'received:rangi.cloud': 0.16; 'situations.': 0.16; 'subject:code':
0.16; 'values,': 0.16; 'want,': 0.16; 'wrote:': 0.16; 'python':
0.16; 'values': 0.17; 'instead': 0.17; 'calls': 0.19; 'pm,': 0.19;
'to:addr:python-list': 0.20; 'returns': 0.22; 'code': 0.23;
'idea': 0.24; 'seems': 0.26; "isn't": 0.27; 'function': 0.27;
'>>>': 0.28; 'header:User-Agent:1': 0.30; 'code,': 0.31;
'approach': 0.31; 'effect': 0.31; 'module': 0.31;
'header:Organization:1': 0.31; 'program': 0.31; 'think': 0.32;
'but': 0.32; "i'm": 0.33; 'there': 0.33; 'header:In-Reply-To:1':
0.34; 'question.': 0.35; 'count': 0.36; 'functions': 0.36;
'thanks,': 0.36; "skip:' 10": 0.37; 'really': 0.37; 'using': 0.37;
'received:192.168': 0.37; 'could': 0.38; 'two': 0.39; 'quite':
0.39; 'text': 0.39; 'use': 0.39; 'break': 0.39; 'difficult': 0.40;
'want': 0.40; 'should': 0.40; 'tell': 0.60; 'remember': 0.61;
'above': 0.62; 'skip:\xc2 10': 0.62; 'subject': 0.63; 'skip:m 20':
0.63; 'received:51': 0.64; 'thus': 0.64; 'with:': 0.64;
'process.': 0.65; 'produce': 0.65; 'wish': 0.66; 'shows': 0.67;
'generator': 0.69; 'latter': 0.69; 'lifting': 0.69; 'sequence':
0.69; 'surrounding': 0.69; 'times': 0.69; 'within': 0.69;
'compared': 0.71; 'skip:* 10': 0.71; 'yourself': 0.75; 'skip:f
20': 0.75; 'produces': 0.76; 'names,': 0.81; 'principles': 0.81;
'(please': 0.84; 'catch': 0.84; 'continued,': 0.84; 'dozen': 0.84;
'jon': 0.84; 'method,': 0.84; 'remind': 0.84; 'scope': 0.84;
'caused': 0.86
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud 29AF8210E
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1668410740;
bh=WzBbpJnqErcy8huNNXCFP9rLlnxlDWh+yXQ7iV6wnmY=;
h=Date:Subject:To:References:From:In-Reply-To:From;
b=Tw63GlB9ZHWE1iLRfz/v1qpEugKH3bJya6GBxmeLKJmw5VRSClDSsC1gFbExvVOEo
ko/bZytduwquGGtxM+Ns3aUgSOggO6a03wXrgzU9ewR+R2oRMmx5WTI8CijYgMF4yf
qyMbmv8/9uR8D494geaQmhDT2EUNkNjywaLDE8N2YlBB8oCADPseJ2Q8bc/O/fkbT8
UXO/UETeUU9b6ZwBxJOkUg9y6kU1WDlV0nhv0wtpMx2M7jW0fPq87bqN9+mMRNqTDf
ZMT0pDtyjkaCHKiGEAXiScKyOnC8Hd03WtYl8oCb2yAEATa0c3TVxotchE08Dl6FJF
Cxs47h52lvl2A==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Content-Language: en-GB
In-Reply-To: <zRecL.17115$Z3L9.382@fx41.iad>
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: <f367ab58-3cdb-a2e8-546e-11238999654a@DancesWithMice.info>
X-Mailman-Original-References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
 by: dn - Mon, 14 Nov 2022 07:25 UTC

On 14/11/2022 12.12, DFS wrote:
> On 11/13/2022 5:20 PM, Jon Ribbens wrote:
>> On 2022-11-13, DFS <nospam@dfs.com> wrote:
>>> In code, list.clear is just ignored.
>>> At the terminal, list.clear shows
>>> <built-in method clear of list object at 0x000001C9CFEC4240>
>>>
>>>
>>> in code:
>>> x = [1,2,3]
>>> x.clear
>>> print(len(x))
>>> 3
>>>
>>> at terminal:
>>> x = [1,2,3]
>>> x.clear
>>> <built-in method clear of list object at 0x000001C9CFEC4240>
>>> print(len(x))
>>> 3
>>>
>>>
>>> Caused me an hour of frustration before I noticed list.clear() was what
>>> I needed.
>>>
>>> x = [1,2,3]
>>> x.clear()
>>> print(len(x))
>>> 0
>>
>> If you want to catch this sort of mistake automatically then you need
>> a linter such as pylint:
>>
>>    $ cat test.py
>>    """Create an array and print its length"""
>>
>>    array = [1, 2, 3]
>>    array.clear
>>    print(len(array))
>>    $ pylint -s n test.py
>>    ************* Module test
>>    test.py:4:0: W0104: Statement seems to have no effect
>> (pointless-statement)
>
>
> Thanks, I should use linters more often.
>
> But why is it allowed in the first place?
>
> I stared at list.clear and surrounding code a dozen times and said
> "Looks right!  Why isn't it clearing the list?!?!"
>
> 2 parens later and I'm golden!
It looks 'right' because it is 'right'!
However, compared with what was intended, it was 'wrong'!

«
I really hate this d***umb machine,
I wish that they would sell it.
It never does quite what I want,
but only what I tell it!
»

Lifting some text from a recent PUG-meeting:

«Distinguishing functions and their names:

Please remind yourself that is_odd is the name of a function, whereas
is_odd() calls the function and could thus be considered a 'label' for
the returned-value – either approach could be used in different situations.
»

In this case, the subject is a method, and accordingly has a slightly
different flavor. Rather than a return-value, the impact is an effect
within the scope and/or to the state of the object. However, not
materially-different from the OP's question.

It is assumed that there is no difficulty related to calling the
function, eg len( x ).

So, why would we use the function/method by name instead of its asking
for its return-value?
(please remember that a Python function is a "first class" object)

The (above) Challenge to PUG-members was to use code which produces the
Fibonacci Sequence, and out of the first 16 values, return the number of
Fibonacci-values which are also odd-numbers.

We started with straight-line code which mixed-up these various steps in
the process. As the challenge continued, such tangling made it very
difficult to enable any variations. To illustrate the SRP and DIP
(Single Responsibility and Dependency Inversion Principles of SOLID
Architecture), we refactored and refactored, ending-up with:

values_counted = sm.sequence_select_and_project(
fg.fibonacci_generator,
is_odd,
limit,
)

sequence_select_and_project is a for-loop spanning two if-statements
which count or break
fibonacci_generator is self-explanatory (hopefully)
is_odd returns boolean advice
limit is 16

Note how the first two arguments are [generator-]function names, cf
function-calls!

Now for 'the magic' of a dependency-inverted plug-in architecture:-

If the 16 is changed to 32, we'll be comfortable with the idea that
twice as many values will be generated and considered.

So, think about changing the generator to produce (say) prime numbers.

Alternately, alter the program to count only values divisible by two
(perhaps using "is_even" as function-name).

By 'plugging-in' a different function-name, the above control-routine
can be used with any suitably-lengthy sequence as its data-source,
and/or selection-criteria function!

Accordingly, using the name of a function can be as useful as using the
result of a function-call - even if the latter is far more common.

--
--
Regards,
=dn

Re: In code, list.clear doesn't throw error - it's just ignored

<C-20221114092106@ram.dialup.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: 14 Nov 2022 08:24:45 GMT
Organization: Stefan Ram
Lines: 27
Expires: 1 Sep 2023 11:59:58 GMT
Message-ID: <C-20221114092106@ram.dialup.fu-berlin.de>
References: <akdcL.10609$Sb52.676@fx45.iad> <slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de +Ne8Nn5EidMXvdVf+0Lx2Q6s/JqUPMSiWkGydYASYvjOZz
X-Copyright: (C) Copyright 2022 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, en-US, it, fr-FR
 by: Stefan Ram - Mon, 14 Nov 2022 08:24 UTC

Jon Ribbens <jon+usenet@unequivocal.eu> writes:
>If you want to catch this sort of mistake automatically then you need
>a linter such as pylint:

For comparison, a C program:

main.c

#include <stdio.h> /* printf */

int main( void )
{ printf; }

transcript

main.c: In function 'main':
main.c:7:3: warning: statement with no effect [-Wunused-value]
7 | { printf; }
| ^~~~~~

. Maybe some of the early designers of Python were C programmers.

In VBA, "debug.print" is allowed, having the same meaning as
"debug.print()", while "sin" gives an error: "Argument is not
optional".

Re: In code, list.clear doesn't throw error - it's just ignored

<return-20221114095354@ram.dialup.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Supersedes: <return-20221114095213@ram.dialup.fu-berlin.de>
Date: 14 Nov 2022 08:55:08 GMT
Organization: Stefan Ram
Lines: 13
Expires: 1 Sep 2023 11:59:58 GMT
Message-ID: <return-20221114095354@ram.dialup.fu-berlin.de>
References: <akdcL.10609$Sb52.676@fx45.iad> <slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu> <zRecL.17115$Z3L9.382@fx41.iad> <CAPTjJmqJO5pyYjM_A-eGLyVRdn7B1d3B76mQP0TkEYHkGKCqsA@mail.gmail.com> <mailman.966.1668391885.20444.python-list@python.org> <uwicL.23347$t_J9.22390@fx43.iad> <CABpSurAU-i0PBZoyq+npf6ead+9xt-K60AZEirArLdJwRDJoiQ@mail.gmail.com> <mailman.969.1668401602.20444.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 we0Gkm2/ZaWCpykctFYOgAui0pSHx0PnhiTbJJ/4wKkQSB
X-Copyright: (C) Copyright 2022 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, en-US, it, fr-FR
 by: Stefan Ram - Mon, 14 Nov 2022 08:55 UTC

Supersedes: <return-20221114095213@ram.dialup.fu-berlin.de>
["evaluation of a function" -> "evaluation of an expression"]

Michael Speer <knomenet@gmail.com> writes:
>Python doesn't care what an expression returns.

In my English, functions return values,
expression are being evaluated to a value.
The evaluation of an expression yields or
produces a value. Expressions do not return,
because they are not functions.

Re: In code, list.clear doesn't throw error - it's just ignored

<expression_stmt-20221114100119@ram.dialup.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: 14 Nov 2022 09:02:17 GMT
Organization: Stefan Ram
Lines: 26
Expires: 1 Sep 2023 11:59:58 GMT
Message-ID: <expression_stmt-20221114100119@ram.dialup.fu-berlin.de>
References: <akdcL.10609$Sb52.676@fx45.iad> <slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu> <zRecL.17115$Z3L9.382@fx41.iad> <slrntn333b.4623.jon+usenet@raven.unequivocal.eu>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 3ABprYhDlzq5DGOoOEM6pgAoCpT1MSRdkV4R3Uga/HQaQf
X-Copyright: (C) Copyright 2022 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, en-US, it, fr-FR
 by: Stefan Ram - Mon, 14 Nov 2022 09:02 UTC

Jon Ribbens <jon+usenet@unequivocal.eu> writes:
>Because it's an expression, and you're allowed to execute expressions.

Yes. This is the dynamical point of view. There's also a
statical point of view, i.e., mere syntax, which is, in
this case, "expression_stmt ::= starred_expression".

|7.1 Expression statements
....
|expression_stmt ::= starred_expression
| |An expression statement evaluates the expression list
|(which may be a single expression).
| |In interactive mode, if the value is not None, it is converted
|to a string using the built-in repr() function and the
|resulting string is written to standard output on a line by
|itself (except if the result is None, so that procedure calls
|do not cause any output.)
| The Python Language Reference (early 3.9)

So, in interactive mode, it even does call a function,
viz., "repr()".

Re: In code, list.clear doesn't throw error - it's just ignored

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!lilly.ping.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: roe...@roelschroeven.net (Roel Schroeven)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Mon, 14 Nov 2022 10:09:44 +0100
Lines: 63
Message-ID: <mailman.972.1668416991.20444.python-list@python.org>
References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<CAPTjJmqJO5pyYjM_A-eGLyVRdn7B1d3B76mQP0TkEYHkGKCqsA@mail.gmail.com>
<mailman.966.1668391885.20444.python-list@python.org>
<uwicL.23347$t_J9.22390@fx43.iad>
<77f0cd80-5ff2-8b02-ab9f-9b65e2d679bc@roelschroeven.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de udwmKyv0nmi+WTY302eOZwHkzUmuhUN8f9ntMbXw3ukw==
Return-Path: <roel@roelschroeven.net>
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=roelschroeven.net header.i=@roelschroeven.net
header.b=LjkN5dSm; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'this:': 0.03; '(which':
0.04; '2022': 0.05; "python's": 0.05; 'subject:error': 0.07;
'angelico': 0.09; 'instances': 0.09; 'problem.': 0.15; '"don\'t':
0.16; '>>>>': 0.16; '>>>>>': 0.16; 'c++': 0.16; 'evaluated': 0.16;
'ignored.': 0.16; 'once.': 0.16; 'place?': 0.16;
'received:10.202': 0.16; 'received:10.202.2': 0.16;
'received:internal': 0.16; 'received:messagingengine.com': 0.16;
'schreef': 0.16; 'subject:code': 0.16; 'wrote:': 0.16; 'instead':
0.17; 'calls': 0.19; 'pm,': 0.19; 'to:addr:python-list': 0.20;
"i've": 0.22; 'languages': 0.22; 'code': 0.23; "isn't": 0.27;
'function': 0.27; '>>>': 0.28; 'chris': 0.28; 'example,': 0.28;
'header:User-Agent:1': 0.30; 'code,': 0.31; 'language.': 0.32;
'personally': 0.32; 'but': 0.32; "i'm": 0.33; 'there': 0.33;
'script': 0.33; 'header:In-Reply-To:1': 0.34; 'received:66': 0.35;
'mon,': 0.36; 'guide': 0.37; "it's": 0.37; 'others': 0.37;
'handle': 0.39; 'something': 0.40; 'method': 0.61; "there's":
0.61; 'true': 0.63; 'between': 0.63; 'shows': 0.67; 'surrounding':
0.69; 'times': 0.69; 'too.': 0.70; 'dozen': 0.84; 'forgot': 0.84;
'invalid.': 0.84; 'jon': 0.84; 'pointer': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
roelschroeven.net; h=cc:content-transfer-encoding:content-type
:date:date:from:from:in-reply-to:in-reply-to:message-id
:mime-version:references:reply-to:sender:subject:subject:to:to;
s=fm3; t=1668416988; x=1668503388; bh=vLMd5LrFqz+PxWR/kTQd1srw5
purluy6+mN7anjeXsA=; b=LjkN5dSmMvjLh8sfyXR0wVydNSyMwdxohL7rh/7im
msDAfKzupblhWdfKn5xsFUecnVirFr7Bpy+clmBuHoIYkhsDDR57pJo/YZqGgL+o
pJlfp6tCsqrFDyB83wlx5Yx87+2oRHfzI7bHywwSY2UYTzwBeZsrDgzvJ+RX6AiY
WfBY1vQnrve8Tj1JIblwqXDoEwPyyIhG1Iq836ncEO1In1DNxsSEKjv9iuZ8DMlo
wvwDHonSm2P+HA+RKiUPS4IiDYOu1Q1/6Vso/uveibSna+Osfk71dU4gjh/2BDce
Ka2QWM0ZiHYv3ah72VKt14ylqWHtMu5wR97sx8Avw74sQ==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
messagingengine.com; h=cc:content-transfer-encoding:content-type
:date:date:feedback-id:feedback-id:from:from:in-reply-to
:in-reply-to:message-id:mime-version:references:reply-to:sender
:subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender
:x-me-sender:x-sasl-enc; s=fm1; t=1668416988; x=1668503388; bh=v
LMd5LrFqz+PxWR/kTQd1srw5purluy6+mN7anjeXsA=; b=T42fXC8SzEspRgU72
pC80qH7XVWt1UC8SvyorKR+GF2+v/ld8FANF70zoZ0zO7xP7cPGStjlBa1AGClnS
0Ty88VrM7+WuZeRSYQ+ZpzxX1qxJBGCbc0VCYJGIZM54pJ/GCemosg8AtDsEfJ/V
EYn3bP9sb3tOMhGH8I8Bc4bVgX7b0bi5fCqgvZ0GrZuvywQn4aGazAp4aa0MyBNu
C4XuGuLER/QLdhjtFBt7/azZuB/62lftSnjIdc/MfsZz7VC19uK2CJMf86Rzs+3c
JS2DoUL2mvy4lJa7pPY9HGVYZOsiLtudrACSxbK2Qsk/8BHeutZAmxAs4MnKhAfr
gGM0A==
X-ME-Sender: <xms:3AVyY9Ky6TCB0I8ju2JU2JnAGMnHL-0rls3yVDHiomDbYFavHoHjEA>
<xme:3AVyY5LrtweMYOOmWlkDYMKHNdqXSMpp9dwOuY2gmsHt09IKhMzWyD1HHJSI2baJe
AmIvH4lGHj8>
X-ME-Received: <xmr:3AVyY1vR7ESvGtyA-4bF1nwj1P4BaR7JyCy0Onh2Y3ANllOjdDtxJi5C7DIh_nJ9GUTG0_mBj7qAf6JkFQER7RzygVAJY4H14vRyvjKFqE7_xfc>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrgedugdduvdelucetufdoteggodetrfdotf
fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen
uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfhuffvfhgjtgfgsehtke
ertddtfeejnecuhfhrohhmpeftohgvlhcuufgthhhrohgvvhgvnhcuoehrohgvlhesrhho
vghlshgthhhrohgvvhgvnhdrnhgvtheqnecuggftrfgrthhtvghrnhepheejudelheeuke
evveeigfelvdegleejtdekfeeluefhiefgkefffffhtdfhhfetnecuvehluhhsthgvrhfu
ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhhovghlsehrohgvlhhstghhrh
hovghvvghnrdhnvght
X-ME-Proxy: <xmx:3AVyY-ZRtEt4b2OhzHQttr-ncEg28tuB_x40kcQsn6IG_tzeFtZYUw>
<xmx:3AVyY0ZHp22OY17wSrj17IBahDQ9IAiGnJGjkjLX4izh4oFm553nXQ>
<xmx:3AVyYyDZsOMpQ4iwol-efihTUuRR3P-FgO4hT91e337JOJ865Cho0A>
<xmx:3AVyY60-42O8o_htA_PfKY89JsDFaWxuzqiJ-2mQ9Q8ndThiM2Jbkg>
Feedback-ID: i8e5b41ae:Fastmail
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Content-Language: nl
In-Reply-To: <uwicL.23347$t_J9.22390@fx43.iad>
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: <77f0cd80-5ff2-8b02-ab9f-9b65e2d679bc@roelschroeven.net>
X-Mailman-Original-References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<CAPTjJmqJO5pyYjM_A-eGLyVRdn7B1d3B76mQP0TkEYHkGKCqsA@mail.gmail.com>
<mailman.966.1668391885.20444.python-list@python.org>
<uwicL.23347$t_J9.22390@fx43.iad>
 by: Roel Schroeven - Mon, 14 Nov 2022 09:09 UTC

Op 14/11/2022 om 4:23 schreef DFS:
> On 11/13/2022 9:11 PM, Chris Angelico wrote:
>> On Mon, 14 Nov 2022 at 11:53, DFS <nospam@dfs.com> wrote:
>>>
>>> On 11/13/2022 5:20 PM, Jon Ribbens wrote:
>>>> On 2022-11-13, DFS <nospam@dfs.com> wrote:
>>>>> In code, list.clear is just ignored.
>>>>> At the terminal, list.clear shows
>>>>> <built-in method clear of list object at 0x000001C9CFEC4240>
>>>>>
>>>>>
>>>>> in code:
>>>>> x = [1,2,3]
>>>>> x.clear
>>>>> print(len(x))
>>>>> 3
>>>>>
>>> But why is it allowed in the first place?
>>>
>>> I stared at list.clear and surrounding code a dozen times and said
>>> "Looks right!  Why isn't it clearing the list?!?!"
>>>
>>> 2 parens later and I'm golden!
>>>
>>
>> No part of it is invalid, so nothing causes a problem. For instance,
>> you can write this:
>
>
> If it wastes time like that it's invalid.

It's not invalid. In the REPL for example, it does something useful:

>>> x = [1, 2, 3]
>>> x.clear
<built-in method clear of list object at 0x000002947DBBF680>

Others have shown instances where writing a method or function without
calling it are useful in a script too.

There are languages that handle this differently. Ruby, for example,
calls the function/method even when you don't write the parens, if I'm
not mistaken. Personally I don't like that; I much prefer Python's
explicitness in making the difference between the value of a function
and calling that function. Still, there's something to be said for
warnings. I agree with others that such warnings are more the job for a
linter than for the language.

FWIW I've been bitten by this in C++ once. I wanted to write something like

if (some_condition())
    foo();

But I forgot the parens after some_condition, so C++ evaluated the
function pointer (which was non-NULL so evaluated is true in a boolean
context) instead of the return value, and therefore foo() got called
unconditionally.

--

"Don't Panic."
-- Douglas Adams, The Hitchhiker's Guide to the Galaxy

Re: In code, list.clear doesn't throw error - it's just ignored

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: Karsten....@gmx.net (Karsten Hilbert)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Mon, 14 Nov 2022 11:46:14 +0100
Lines: 11
Sender: <karsten.hilbert@gmx.net>
Message-ID: <mailman.973.1668422777.20444.python-list@python.org>
References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<slrntn333b.4623.jon+usenet@raven.unequivocal.eu>
<jtdi03Fi4kqU1@mid.individual.net>
<0b97e354-49a3-f7bb-a3bb-3f2f6024ae68@mrabarnett.plus.com>
<Y3IcdnRmLGpQKc6F@hermes.hilbert.loc>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de IafnOG6pK1lILti6v3beTwo6sm5YBDR7pRDEwbaxFHsA==
Return-Path: <karsten.hilbert@gmx.net>
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=gmx.net header.i=@gmx.net header.b=rfK0cHpV;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '2022': 0.05;
'received:212.227': 0.07; 'subject:error': 0.07; 'expression':
0.09; 'gpg': 0.09; 'karsten': 0.09; 'schrieb': 0.09; '1713': 0.16;
'call,': 0.16; 'received:212.227.15': 0.16; 'subject:code': 0.16;
'probably': 0.17; 'to:addr:python-list': 0.20; 'suitable': 0.32;
'but': 0.32; 'header:In-Reply-To:1': 0.34; 'mon,': 0.36; "it's":
0.37; 'received:212': 0.62; 'received:91': 0.62; 'out.': 0.80
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417;
t=1668422775; bh=ujhfCUct73fxP90BTwPQF0wlNKMeQ5ttNrPwMchFRmE=;
h=X-UI-Sender-Class:Date:From:To:Subject:References:In-Reply-To;
b=rfK0cHpVTqKaNnam19PRI6uNmt3qY33kNrKF20Jor1Rv8QSK/qh3XJDBHfQ40lcx+
DHxEP3UnmvRcvZDksZkizYHLgJUYtbSEseUeaclIfOD/dzVnkxBC2zQmyr7VLGv0nF
xBhXCSxAtR2QOpDV2ANYqIXGMxlAlQrj4akt7KVLzktAb2gN/T5O2ywAJFYUx2Javj
OT+31Xd3uBME5JI7DTDloVd1HEQpEiXW/pG1SQ2nwmgHWeXa9QLDUM7SUM/rtdsIK1
NyFgzx73ejle5myDO4f0tnKPFhW/IojpNWQWIJssbddUNx8Lx12okz91EFyfoZ/9Ya
7SHPp/ppqctYA==
X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a
Content-Disposition: inline
In-Reply-To: <0b97e354-49a3-f7bb-a3bb-3f2f6024ae68@mrabarnett.plus.com>
Ma_X_il-Followup-to: d
Re_X_turn-receipt-to: Karsten.Hilbert@gmx.net
Di_X_sposition-Notification-To: Karsten.Hilbert@gmx.net
X-Confi_X_rm-Reading-To: Karsten.Hilbert@gmx.net
X-Pri_X_ority: 2 (High)
X-Provags-ID: V03:K1:m99f5XqqX/yZ/kwZSgSGugyY1x7T7M3fiDrC0cMFZ4cGyPJxP2W
O21wFGRHCMvQkeJfb7j1ZQTPdLRpLApkjkpV293De7xkVSfJmTl5peMtRiiHtHFrD8LMvdK
SJcCagrFeZmwhoqaHP6XhyvMTb57a1UiiP0WGUSIOi9PYUAJzwBiAlqtqXyJnW3Tm6rE946
P25kB0wiG7VXeRJChQgKA==
X-Spam-Flag: NO
UI-OutboundReport: notjunk:1;M01:P0:Nq7l2H1M0Rs=;HkArZe6T4wpZxtofyQZkNCFyXnh
5moFjNSm7OJOyTgcG5ZIvwJXNT1TIe6msGymmIGm8I68dL1JRscevvCneCxU8R35Y7eQHNjpH
HADNmKTkSK9eTBUEJzbM0DQOtuUGhkHaB1wed1LSb1/0i8N9tp5+0W5DFskRvljKuvYTreesT
cTuicS4Sml4cij0ZWYW9iaOW1Q28efy6s7U16wBLMFpYJUniDFMQM4pN7A8B5WkXPUbIJyQPw
CFEgEVj+sNeLdPo2EhbQTr7dro5F+htKZ/ECOpOVmqFN8yA48gZGnq2ZzBdCW2M6D8VPPLBnY
9IUkpTvyXFMBR6hvwjIHhBXcqkN5DgKXyEpPq6l5/5JRqRHd0DfozWu3i80E+kOZwoNa49xzm
hZW1S3osd/Td/74s7I9KSwBKw3hN1k/hiVSlr3JVlMmnF8cbL89KvNfP8TzkAL7ZR05YfpL3c
xE/rcxc6F93WHVQ2ADG70W+naEqF2VtpvQMi7f8aWCOutNwqOFz741UpJJSCLdH/WwJOHCbYh
h2OpPHAjOxWMy3dGHQzTza+GKWmceDCeTuSeKNoS+YKj5Yb8mwO+5/dLpAWXsaK0jXxkPd50P
eivOPrT6f5BodyAyGEicdi3lGfZOouQiK0O/KZ3aYzsOiIxadywv8b5Va3GjlvSwmI3ykGkl6
ZC4SB/gJ7GUyfKNLCH3fTTca5J2NTB0bG9At4wZ6lxQyHNFQyGiyFIJFdbA5r88GHZcS3yHGd
mKGhEzL4lRMiyNPPrXwYWsk93wX+mU/sFWq0xG0zhdkyBBMpxwViFIhyY1dpn3y67LW09jBmq
O30oKJbs1AQRybR1TU05/sv937GJGGsv/ycPD1kQuspaRC0eUXWr8N5UmFZ5cQPwsJQJStPQL
3GRCOkMBWHGmLHitP7yspgYegR8V193rNX2c9Lv4IisgHmnEPneJc2ONChhml3iTshaJjSWHG
fS0oxQ==
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: <Y3IcdnRmLGpQKc6F@hermes.hilbert.loc>
X-Mailman-Original-References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<slrntn333b.4623.jon+usenet@raven.unequivocal.eu>
<jtdi03Fi4kqU1@mid.individual.net>
<0b97e354-49a3-f7bb-a3bb-3f2f6024ae68@mrabarnett.plus.com>
 by: Karsten Hilbert - Mon, 14 Nov 2022 10:46 UTC

Am Mon, Nov 14, 2022 at 02:13:34AM +0000 schrieb MRAB:

> But if it's an expression where it's expecting a statement and it's not a call, then
> it's probably a bug.

That "probably" makes it suitable for a linter, as was pointed out.

Karsten
--
GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B

Re: In code, list.clear doesn't throw error - it's just ignored

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.mixmin.net!news2.arglkargh.de!news.karotte.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: gweathe...@uchc.edu (Weatherby,Gerard)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Mon, 14 Nov 2022 11:35:26 +0000
Lines: 55
Message-ID: <mailman.974.1668425739.20444.python-list@python.org>
References: <akdcL.10609$Sb52.676@fx45.iad>
<SA1PR14MB585535430D538858958B1DD0B9059@SA1PR14MB5855.namprd14.prod.outlook.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de uz2CZYXSYoHUTkz6t3mmAQ/IbvDKNmPeYP8yaMZGsmbQ==
Return-Path: <prvs=0317fbcd47=gweatherby@uchc.edu>
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=uchc.edu header.i=@uchc.edu header.b=W+6lSO2/;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.076
X-Spam-Evidence: '*H*': 0.85; '*S*': 0.00; '(e.g.': 0.05; '2022':
0.05; 'subject:error': 0.07; 'received:namprd14.prod.outlook.com':
0.09; 'terminal': 0.09; 'url:mailman': 0.15; '***': 0.16;
'frustration': 0.16; 'ignored': 0.16; 'ignored.': 0.16;
'subject:code': 0.16; 'url:urldefense': 0.16; 'url:v3': 0.16;
'python': 0.16; 'to:addr:python-list': 0.20; 'to:name:python-
list@python.org': 0.24; 'url:listinfo': 0.25; 'seems': 0.26;
'object': 0.26; 'opening': 0.26; 'received:edu': 0.26; 'function':
0.27; 'email addr:python.org&gt;': 0.28; 'error': 0.29; 'code,':
0.31; 'effect': 0.31; "doesn't": 0.32; '13,': 0.32; 'python-list':
0.32; 'header:In-Reply-To:1': 0.34; 'header:Received:8': 0.36;
'received:filterd': 0.37; 'received:pps.filterd': 0.37; "it's":
0.37; 'url-ip:13.107/16': 0.38; 'date:': 0.39; 'list': 0.39;
'use': 0.39; 'ide': 0.40; 'try': 0.40; 'charset:windows-1252':
0.60; 'email.': 0.61; 'method': 0.61; 'skip:0 20': 0.61; 'from:':
0.62; 'to:': 0.62; 'clear': 0.64; 'shows': 0.67; 'items': 0.68;
'it:': 0.69; 'url-ip:52.6/16': 0.69; 'del': 0.70; 'clicking':
0.76; 'links.': 0.81; 'attention:': 0.84; 'email name:&lt;python-
list': 0.84; 'skip:& 50': 0.84; 'was.': 0.84; 'caused': 0.86
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uchc.edu;
h=from : to : subject :
date : message-id : references : in-reply-to : content-type :
mime-version; s=UCHC03162020;
bh=7NpkL/nVvmjfH7x8GEJRp0b+2eSM+CCVXtwQQVMicwc=;
b=W+6lSO2/rD2o076F95RXKeZq8wos/CEK8x2xUi7ZpDTdrGdwqt4pXBsCEu/zfMgM5o53
bWY+3+MAZLpEfic5UnLsUCei15JjUOYN6291NauKuJqfe3HagGdq82uQE8nsIycOHOWQ
LLws80U6H8j44aNbXC/sHb0YKTl1JGLlcPaE5nIUfoV4pKwB21uKzqmrl8RhlkLg6Kt/
fgBoBV5A5JAxWzrth+GPmwjqiy7fCrHF6c+SHG4HlwW5ymExbbRgojSSL0lI78pWww4o
Z/TJ8gGlPz2x+OJiMH7XFW64nXiPcC2FFKO3+oxiAreCRsK9E5BY6q1l6Hfmc8azj/Yg Bw==
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
b=Tyfs1DAMh0Mf69x1vdHufZ6gVpCkFd45VidE2EfTL3qEExGXUle0bQUL2lq4TpANEJud4wymDSBoNg38uOmPZS++HKMeCNPp5t0eBN4Dd1MF6x/caHNrCBOtxFr7gGLPn/8suFQPwJ7P/aeYlwvQ2zKEU0hgCr8Gm6SBBMKrCSUB9TXXYbxahAwmojqyrX9qqTUEfHZK0BxSwWv3+LAVOleS7xFYAJKu60oBUbIVGJp/6npvIBka0OsM1IONn0oLwtjL2F84ABSbjd2hWoiNi5dHZhTRVDRKpZ74IWCZbyTdze3Ai2+6mP/vznUxXI/ZONxyxUR5AgF59t5kaPHuIw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
s=arcselector9901;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
bh=7NpkL/nVvmjfH7x8GEJRp0b+2eSM+CCVXtwQQVMicwc=;
b=J3msyq1XT2uvUt3dNf6VoMznSWIZtAW9wHhqxiSOZIaSioFy0q3s63Z0X0FcuKj2j2ZDHOSGNPhXU1mXmWI20VPr3S9S9UkWtVAMIW/pQYaCxyU4/skVBmLKoQ/PbqMyd1EJo4Ukw+L9TxsA21+ecpmhClKZenTDBksGsCS0M4C184yiF6bz2QhmUIQwqmxzjnLjNUCY5q9v2LORLlEfS8JgtwBVLHTQyezyUUMHzqOhsNECdgLwDCsZkTJA6LdOfOVyd9pkVct8WbV/wMvwjzH0we/V1XVdXFXgTOvbyMl2NrEaF39damnhA+ZDrRoonYXZjE0cmjydIISUWyEbdQ==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=uchc.edu; dmarc=pass action=none header.from=uchc.edu;
dkim=pass header.d=uchc.edu; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uchc.onmicrosoft.com;
s=selector2-uchc-onmicrosoft-com;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=7NpkL/nVvmjfH7x8GEJRp0b+2eSM+CCVXtwQQVMicwc=;
b=iNUku7vuMcXBzBY4JRMMW4xOBZ4y+wqShLozMqKvGNrkP6CqJfc580TQxYEFjjooL3dkkFXe5/lnfjabmX/cchuTdsBCiVWK4u6mUolYVM5OwZrgMSPD6qbES11tqmx2NKAM/IjZAaTq//QPQPzgkyITO16aig1IDkX9nejmFDM=
Thread-Topic: In code, list.clear doesn't throw error - it's just ignored
Thread-Index: AQHY98KFR5OqC1qFakK95/cdZ/drNq4+SX4V
In-Reply-To: <akdcL.10609$Sb52.676@fx45.iad>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
x-ms-publictraffictype: Email
x-ms-traffictypediagnostic: SA1PR14MB5855:EE_|DM6PR14MB3385:EE_
x-ms-office365-filtering-correlation-id: 911f443d-89f5-4674-46ac-08dac634539f
x-ms-exchange-senderadcheck: 1
x-ms-exchange-antispam-relay: 0
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: amI/Ws+cTNbvS/g6KPsAK9Ko9tXlRJkcsoSenhjUFp+1GRXyrXk1ras0xbn+akD4QSKXHQuRnbPwHNzu+m1Y4Z1KhFfEbrV+vTFoxL3/tsy03YyN7nHJhYZz6cDM4c+HDNcovSbiQte8Vuc7r9XpK80o3v3Ik6qxSzxQp3d9GnK/9jS9G9/CpA4QidRdYnprBLx5z2BIGqaRKRc6m8p+IdQaItDV3s3X/shbdrbpC+WtoppRQkGSINNpQ08lzFlVPOpMZWLu+onGeveUSdDv+L1SJa9Lt/Lho5sLqbFOV3vIC9eW1bE3+vgzZ2pu1+D5/HO8e9/lFSo0OAouN3VF/vRgjgjC0DCVFGZ2LrzWtVDRBaOVrTEu0ljvCf4raSdUoeWXkLnR8tggBzxgIFFx4J6nC9IwAVNZxcowF1BEXoDaEwYgRbAQosAdUB+kig8xCLqQIlIiSu/SdGrYarZuI74zTOfoJReQdUVaiWmUO+uSIY4GfzYGp0/vuXk3ftJWSs7Kea6Lslf9N0nR3BY4yBfNoieui/Vk19bHjg9xYPHIwfX0T6PUddqpw6JbYHphtcqxudm6gaKMUnyTRyrT9uwvWei7C8vMfXsBh4JxrvSpNBiCW2O7Xo8vuJGF3TyVG3Wn+rRuWuv9m1VHlldeWIg0UgRSSkq2nAtHNHkbKIAZ86qAiXTmI5RXOgv7J8Js/lgVdyWQjlZirnm0amFTWPGqNIv2ky082EtSRDAYSx7WUX5WPU78wSeLrhh/s+C5ibbq95eruxc8T4sxFvjF/G+/DZJks4WzVVbO8uNEV7w=
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:SA1PR14MB5855.namprd14.prod.outlook.com; PTR:; CAT:NONE;
SFS:(13230022)(39850400004)(396003)(376002)(346002)(136003)(366004)(451199015)(86362001)(6506007)(9686003)(53546011)(2906002)(7696005)(38070700005)(966005)(478600001)(41320700001)(26005)(33656002)(71200400001)(55016003)(5660300002)(75432002)(122000001)(41300700001)(21615005)(91956017)(52536014)(76116006)(38100700002)(66556008)(64756008)(66446008)(8676002)(186003)(66476007)(66946007)(166002)(83380400001)(8936002)(786003)(6916009)(316002);
DIR:OUT; SFP:1101;
x-ms-exchange-antispam-messagedata-chunkcount: 1
x-ms-exchange-antispam-messagedata-0: DF5OiKXNfmqnRFXRZiKcdLzFxOQCHzbYRQX50brCPs0njvag6vwqMnIF
TA/ySjwWsC5N0ql71IYFglUsVrgeqvStOuqg1ePB93Cw+l9VEhfmwCeN
1iluQGQB/Lkpq6cvrwscKI1qOjbnGUE0rQqWvcEQeXYkdcYCclV0XNzN
6zDh9CYMbegO+u4yA+mw/W4Ll+U8LUPzBftBFAlXt3rR30jq0Qb8LaDe
y5jguUW1leLmt1JXx3o9CVeIG8xMmdWFMGhSAo7hTOuMm681RUrONGE3
1USbqLRLcDWVaNnZDbU6jjiI37CGzX6nKjjJU9KOJmb263age3ZeIU5z
XysWjfKJmujtPV2fgaAOV/sM7ozFFgWHjJNoBzgRxbMonI/jzMDxedO2
6IEaOBmOlvCCSetxm7rLmClgEmDAYgUB+hVRKFe+N0buwUDiRxtkowsl
ts4K4dXJB8xK+86T4TwVftXTWu9cNHVZ4JCjiUxoS6/e/xqF3cRpZ4xZ
9ThUj3gkXeYH7bQ0o/2trZMRw/on4AmARigAnIaIEIKa9ezzhNP3buky
cJIk9dyJ3eDrH4wQlhbW4aNZQ/Bb3fnLnT+XlbkVbO3hH1rpcVC31rb2
koJNjT5CdNpY8ZPqtWyOg3W521FltKWk3fj9KavGkq49ev/b+tZfVUmC
dub1hAy40mOuVtC6yQvXuJrnnOMjjRFZ091TU1rjuKJF4kHo8mTY2vXS
/b9QEIA+gAJaIQuCX+Hlu/nm42TGPMy02LHfa/Wv8psWHvu5h/BF1Lpp
kG0PvLMA6VugtP40fpDH+ztWzjshNLYlqAX5FJ1/R6bCHfUgSc4YUqUc
+tMCHMK8yg5GDZzO0sZJ5n1UiUhGA9IrSI8+R0JbofY0m3uVLnVaTT+N
aDRfsPoahOB+N3dU/8TzIkOulPP3/mpeTm+7TnRu7nS53H4uGXWvKlpt
REnXJTNnNUbOTlAmkrCx93ESLP6WbWBFU0ExKB0HLLc9FCxv2NFmxW3m
OM8zWEg8NCxTRJkHYPVyq1LLImzZVZNLozrsuYw+v0nLlIDH+joeUqms
12P69WI4AYvBWXCOuw03pf5jCyVmUJa9Rm/XTJeQG1drEg1o93/Txhd7
Fl842dFrO+PRY4fWlK9QsyHUQfQTyoJwFZCMUW5c9UbBi5tEJAFgJxEY
9/jwl4McbNcrJJJEsYOaOWnfAtCwPJ1leYopmh4NuqZovDAot9E4Hwgy
GA4YyJ0LmXsOejF9qeEnc4kpLW4CtqYR80QFseJR4fzMv0kYJ+Ryaehn
r7hjyPwlu2itbHZYjhQxEuJYphpsFuFT10MOep9jFl0XEZPh4ZfL+h7B
y3LUG+clNKTVbonsJIXbLQFFHj0MQScVfhpkgS9MjGENhcdFUA2zxyz6
2GIWWntdkALmXmcBjgVyIw1kiWoRzH4Pnb+QHe48D5GaI6QVn+5hdygi
5iUvDg/fFUC8aDNhfb7daFxqs6gBLOxkhdNgLHWUBy6rulG67W73wRf5
sRRKjdurbM3KoeH/Y7DgAe5IjtU3VBCiZ7lTxNUAxCft++oIDBCEwmUe
DXW6Zzs+fxHGVdpnMgmVD4DN0OBybEAXSprKHSzS7jmJnx5iMh8kEA
==
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: SA1PR14MB5855.namprd14.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: 911f443d-89f5-4674-46ac-08dac634539f
X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Nov 2022 11:35:26.9580 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 5c82d83a-818a-4c16-b540-ded2344a7ad3
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: RP0BI4d30Bh5xuBwcz19xyW/fjL6dZll4+WSo2lASHnuqH3eildi6GbfecA3FnB0jkfzhedfop4jgqDlar4tUg==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR14MB3385
X-Proofpoint-ORIG-GUID: flj2oOoEjuEUUaQddwRoiPuxbdhlDTM8
X-Proofpoint-GUID: flj2oOoEjuEUUaQddwRoiPuxbdhlDTM8
X-Proofpoint-Virus-Version: vendor=baseguard
engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1
definitions=2022-11-14_10,2022-11-11_01,2022-06-22_01
X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0
lowpriorityscore=0 mlxscore=0
priorityscore=1501 impostorscore=0 adultscore=0 malwarescore=0 spamscore=0
clxscore=1015 phishscore=0 bulkscore=0 mlxlogscore=808 suspectscore=0
classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000
definitions=main-2211140084
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: <SA1PR14MB585535430D538858958B1DD0B9059@SA1PR14MB5855.namprd14.prod.outlook.com>
X-Mailman-Original-References: <akdcL.10609$Sb52.676@fx45.iad>
 by: Weatherby,Gerard - Mon, 14 Nov 2022 11:35 UTC

The terminal told you what x.clear was.

The Python documentation tells you how to call it: https://docs.python.org/3/tutorial/datastructures.html

list.clear()
Remove all items from the list. Equivalent to del a[:].

An IDE (e.g. PyCharm) will try to autocomplete the parentheses and warn you if you don’t:

“Statement seems to have no effect and can be replaced with a function call to have effect”

From: Python-list <python-list-bounces+gweatherby=uchc.edu@python.org> on behalf of DFS <nospam@dfs.com>
Date: Sunday, November 13, 2022 at 7:46 PM
To: python-list@python.org <python-list@python.org>
Subject: In code, list.clear doesn't throw error - it's just ignored
*** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. ***

In code, list.clear is just ignored.
At the terminal, list.clear shows
<built-in method clear of list object at 0x000001C9CFEC4240>

in code:
x = [1,2,3]
x.clear
print(len(x))
3

at terminal:
x = [1,2,3]
x.clear
<built-in method clear of list object at 0x000001C9CFEC4240>
print(len(x))
3

Caused me an hour of frustration before I noticed list.clear() was what
I needed.

x = [1,2,3]
x.clear()
print(len(x))
0

--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!jRrjG0fRo46VyY0jLfD1Z5C6tXDiphZy8zi2AqN_N5BB1_OwBe_wxmsBWmIVOFQDdZnvbRq1JNeGnPg$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!jRrjG0fRo46VyY0jLfD1Z5C6tXDiphZy8zi2AqN_N5BB1_OwBe_wxmsBWmIVOFQDdZnvbRq1JNeGnPg$>

Re: In code, list.clear doesn't throw error - it's just ignored

<expression-20221114150121@ram.dialup.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: 14 Nov 2022 14:01:41 GMT
Organization: Stefan Ram
Lines: 14
Expires: 1 Sep 2023 11:59:58 GMT
Message-ID: <expression-20221114150121@ram.dialup.fu-berlin.de>
References: <akdcL.10609$Sb52.676@fx45.iad> <slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de Q1/DvJPZVi3N/ZmxOjMIOwLskmv2v3KTSAxsiuRORp/dAL
X-Copyright: (C) Copyright 2022 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, en-US, it, fr-FR
 by: Stefan Ram - Mon, 14 Nov 2022 14:01 UTC

Jon Ribbens <jon+usenet@unequivocal.eu> writes:
>"""Create an array and print its length"""
>array = [1, 2, 3]
>array.clear

BTW: Above, there are /two/ expression statements
with no effect; the other one is

"""Create an array and print its length"""

. Apparently, linters know this and will not create
a warning for such string literals.

Re: In code, list.clear doesn't throw error - it's just ignored

<OO-20221114150728@ram.dialup.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: 14 Nov 2022 14:07:57 GMT
Organization: Stefan Ram
Lines: 11
Expires: 1 Sep 2023 11:59:58 GMT
Message-ID: <OO-20221114150728@ram.dialup.fu-berlin.de>
References: <akdcL.10609$Sb52.676@fx45.iad> <slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu> <expression-20221114150121@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de pprBnbyKZwTF343lAhROoQwPLKyT15TLm3bQ443O8Dh1Vo
X-Copyright: (C) Copyright 2022 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, en-US, it, fr-FR
 by: Stefan Ram - Mon, 14 Nov 2022 14:07 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>BTW: Above, there are /two/ expression statements
>with no effect; the other one is
>"""Create an array and print its length"""
>. Apparently, linters know this and will not create
>a warning for such string literals.

And Python is reported to remove such string
statements when invoked with "-OO".

Re: In code, list.clear doesn't throw error - it's just ignored

<slrntn4jhh.4623.jon+usenet@raven.unequivocal.eu>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: jon+use...@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Mon, 14 Nov 2022 14:18:25 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <slrntn4jhh.4623.jon+usenet@raven.unequivocal.eu>
References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<expression-20221114150121@ram.dialup.fu-berlin.de>
Injection-Date: Mon, 14 Nov 2022 14:18:25 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="76996512d30d55fb05ea8fc42ec86161";
logging-data="1874922"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ALL8Ipml2wnsw3nml+4QRW0rR8n1Y4iM="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:3Nq+nUJwirNvyArKv1xnuF+sGRA=
 by: Jon Ribbens - Mon, 14 Nov 2022 14:18 UTC

On 2022-11-14, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
> Jon Ribbens <jon+usenet@unequivocal.eu> writes:
>>"""Create an array and print its length"""
>>array = [1, 2, 3]
>>array.clear
>
> BTW: Above, there are /two/ expression statements
> with no effect; the other one is
>
> """Create an array and print its length"""
>
> . Apparently, linters know this and will not create
> a warning for such string literals.

Not only do they know this, pylint will complain if you *don't* include
that line, which is why I included it ;-)

Re: In code, list.clear doesn't throw error - it's just ignored

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Tue, 15 Nov 2022 06:14:02 +1100
Lines: 17
Message-ID: <mailman.981.1668453254.20444.python-list@python.org>
References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<CAPTjJmqJO5pyYjM_A-eGLyVRdn7B1d3B76mQP0TkEYHkGKCqsA@mail.gmail.com>
<mailman.966.1668391885.20444.python-list@python.org>
<uwicL.23347$t_J9.22390@fx43.iad>
<CABpSurAU-i0PBZoyq+npf6ead+9xt-K60AZEirArLdJwRDJoiQ@mail.gmail.com>
<mailman.969.1668401602.20444.python-list@python.org>
<return-20221114095213@ram.dialup.fu-berlin.de>
<CAPTjJmpqx-MWgUOrajTDOzNJ_JX7wR-GKFGguC+O3=1=t6oN1g@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de 0rI+Q3y/KaJbLJHcQgc/6wK6afw5QpP06ZCTBlo53VSA==
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=knu17mWQ;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.004
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '2022': 0.05; 'ram': 0.07;
'subject:error': 0.07; 'expression': 0.09; 'like,': 0.09;
'writes:': 0.09; 'chrisa': 0.16; 'evaluated': 0.16; 'expressions':
0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'functions.': 0.16; 'received:209.85.208.42': 0.16; 'received
:mail-ed1-f42.google.com': 0.16; 'subject:code': 0.16;
'terminology': 0.16; 'values,': 0.16; 'wrote:': 0.16; 'calls':
0.19; 'tue,': 0.19; 'to:addr:python-list': 0.20; 'stefan': 0.26;
'function': 0.27; "doesn't": 0.32; 'message-id:@mail.gmail.com':
0.32; 'but': 0.32; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'english,': 0.35;
'from:addr:gmail.com': 0.35; 'functions': 0.36; 'received:209.85':
0.37; 'received:209': 0.39; 'received:209.85.208': 0.39;
'evaluation': 0.39; 'michael': 0.60; "there's": 0.61; 'between':
0.63; 'types': 0.67; 'care': 0.71; 'produces': 0.76; 'dispute':
0.84; 'return,': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=MZ90ZlSv6kS6JssYOp+ecaSTiqoNnJhi5iq74//EhE4=;
b=knu17mWQvBR4X6ymMcZMBGLX2dSpMjyZLBxwk2oNv69bEHV2bNAiICGDkE8ABmwDSh
qN2EMSqvXCMPPUZKFAYyXyWctI1FHK0jobjVye+7GFM7zvFRGvVJqP6dbSNJ9Z6oeh/U
FfcOOxlmMajHPF404ImJW/WgP++Q9izmMZv/tivDmR0/eKQuSWkIVAV82uTAgI/7gX0r
hvYQutrCKbElkm6Ni20FAv2J4bz5x4GF04jFxmUecLhLEvZ5XXVSFd6XAneDjYM3FVzo
1Jqcd61r+XbI1JIZPrYspDK5F9M+OhWOWw4hIL/6pxzA603Q9JCqawZJfnalzIVzvvvg
3lMA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
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=MZ90ZlSv6kS6JssYOp+ecaSTiqoNnJhi5iq74//EhE4=;
b=kxSoovhLCjTJmHYTySSnTp0eHeFNRd2yFNggCaqG4vLHvNr4MQfI7wa7W8ge9GsScJ
ClJDfqWW94UATWAzw5/w7VpBEaipUfVwKPuygTqhqLjaV04TnYSzr999APb5Q0xE3+qM
UJ8GF54efGD08TKLoI5ZEoFD2YU3ltzFH+IN1w6l6lXbBuNeh+nDc8xUObeqPLDSr8lr
orvR3/IlHe6EecXkycDlPwk5vb4fHrFyEqlAO+GyFq/D+hSET5rnUovP93hbYO7yZ1Qf
7w/7vB8qlNLlGkgBBP5pwA6wapAV+ITWlCs/AhCNQAJ3aQ4LeXLKehPN7zbjVrLyxi2b
VMig==
X-Gm-Message-State: ANoB5pmIHYM6N177iHqeNr8k6bUdEv0+YciuEmpmjbYjpg0RckK1tIWn
MRNXsNeUb+JAFW65RHt5c1/0T+/8/IS/moYmkVYmINC5
X-Google-Smtp-Source: AA0mqf5t0zlTfUoe/d/bmx3jSKB3YlNbPLZt9ZWU7vUMawOObW+2cnoKt8Zp6opN579pgI3Y2XWGW/K23AEcYyg131g=
X-Received: by 2002:a05:6402:2931:b0:463:ce05:c00e with SMTP id
ee49-20020a056402293100b00463ce05c00emr12280383edb.46.1668453253593; Mon, 14
Nov 2022 11:14:13 -0800 (PST)
In-Reply-To: <return-20221114095213@ram.dialup.fu-berlin.de>
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: <CAPTjJmpqx-MWgUOrajTDOzNJ_JX7wR-GKFGguC+O3=1=t6oN1g@mail.gmail.com>
X-Mailman-Original-References: <akdcL.10609$Sb52.676@fx45.iad>
<slrntn2rd7.4623.jon+usenet@raven.unequivocal.eu>
<zRecL.17115$Z3L9.382@fx41.iad>
<CAPTjJmqJO5pyYjM_A-eGLyVRdn7B1d3B76mQP0TkEYHkGKCqsA@mail.gmail.com>
<mailman.966.1668391885.20444.python-list@python.org>
<uwicL.23347$t_J9.22390@fx43.iad>
<CABpSurAU-i0PBZoyq+npf6ead+9xt-K60AZEirArLdJwRDJoiQ@mail.gmail.com>
<mailman.969.1668401602.20444.python-list@python.org>
<return-20221114095213@ram.dialup.fu-berlin.de>
 by: Chris Angelico - Mon, 14 Nov 2022 19:14 UTC

On Tue, 15 Nov 2022 at 05:57, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>
> Michael Speer <knomenet@gmail.com> writes:
> >Python doesn't care what an expression returns.
>
> In my English, functions return values,
> expression are being evaluated to a value.
> The evaluation of a function yields or
> produces a value. Expressions do not return,
> because they are not functions.
>

Well, you can dispute the terminology all you like, but there's no
real difference between function calls and other types of expression.
They're all just expressions and they can be combined arbitrarily.

ChrisA

Re: In code, list.clear doesn't throw error - it's just ignored

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!lilly.ping.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: cs...@cskk.id.au (Cameron Simpson)
Newsgroups: comp.lang.python
Subject: Re: In code, list.clear doesn't throw error - it's just ignored
Date: Tue, 15 Nov 2022 09:11:10 +1100
Lines: 40
Message-ID: <mailman.984.1668463881.20444.python-list@python.org>
References: <uwicL.23347$t_J9.22390@fx43.iad>
<Y3K8/qP7/xcGSAEu@cskk.homeip.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
X-Trace: news.uni-berlin.de /x74LfUFTGbM26PWyLI8KgNOZCUzuaTFOddtdSE3/cXg==
Return-Path: <cameron@cskk.id.au>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'looks': 0.02; 'this:':
0.03; '(which': 0.04; 'subject:error': 0.07; 'suggestion': 0.07;
'angelico': 0.09; 'expression': 0.09; 'lookup': 0.09; 'skip:` 20':
0.09; 'cheers,': 0.11; 'problem.': 0.15; '(b)': 0.16; 'cameron':
0.16; 'case).': 0.16; 'devs': 0.16; 'effects.': 0.16;
'from:addr:cs': 0.16; 'from:addr:cskk.id.au': 0.16;
'from:name:cameron simpson': 0.16; 'interpreter': 0.16; "isn't,":
0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:13.237':
0.16; 'received:13.237.201': 0.16; 'received:13.237.201.189':
0.16; 'received:cskk.id.au': 0.16; 'received:id.au': 0.16;
'received:l': 0.16; 'received:mail.cskk.id.au': 0.16; 'runtime':
0.16; 'semantics': 0.16; 'simpson': 0.16; 'subject:code': 0.16;
'things,': 0.16; 'wrote:': 0.16; 'python': 0.16; 'probably': 0.17;
'it?': 0.19; 'pm,': 0.19; 'to:addr:python-list': 0.20; "i've":
0.22; 'code': 0.23; "i'd": 0.24; 'actual': 0.25; 'examples': 0.25;
'do,': 0.26; 'object': 0.26; "isn't": 0.27; 'chris': 0.28; 'it,':
0.29; 'header:User-Agent:1': 0.30; 'deep': 0.31; 'personally':
0.32; 'but': 0.32; "i'm": 0.33; 'there': 0.33; 'header:In-Reply-
To:1': 0.34; 'running': 0.34; 'received:au': 0.35; 'those': 0.36;
'special': 0.37; 'really': 0.37; "it's": 0.37; 'way': 0.38;
'this,': 0.39; 'valid': 0.39; 'best': 0.61; 'here': 0.62;
'received:13': 0.64; 'your': 0.64; 'received:userid': 0.66;
'that,': 0.67; 'result,': 0.69; 'through.': 0.69; 'easy': 0.74;
'happens': 0.84; 'known': 0.84; 'attribute': 0.84; 'invalid.':
0.84
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <uwicL.23347$t_J9.22390@fx43.iad>
User-Agent: Mutt/2.2.7 (2022-08-07)
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: <Y3K8/qP7/xcGSAEu@cskk.homeip.net>
X-Mailman-Original-References: <uwicL.23347$t_J9.22390@fx43.iad>
 by: Cameron Simpson - Mon, 14 Nov 2022 22:11 UTC

On 13Nov2022 22:23, DFS <nospam@dfs.com> wrote:
>On 11/13/2022 9:11 PM, Chris Angelico wrote:
>> [ ... `x.clear` ... ]
>>No part of it is invalid, so nothing causes a problem. For instance,
>>you can write this:
>
>If it wastes time like that it's invalid.

It's a valid expression.

It looks to your eye like a no-op, but at actually Python _looks up the
name `clear`_ on an object (which happens to be a `list`). That is a
real thing to do, and can have side effects.

While most of the examples here have been in the REPL where running an
expression with no side effects is itself useful, because the REPL can
print the result, I've personally got some real world code with a bare
`some_object.attribute` line. I'm not sure where, or I'd show it, but I
_think_ it was probably prepriming a cached object property. There might
have been a more expressive way to do that, but it was a bare attribute
lookup with side effects, _used for those side effects_.

>This is an easy check for the interpreter to make.

It really isn't, given that (a) this isn't known by the interpreter to
be a `list` until runtime and (b) that would need embedding special
knowledge that looking up an attribute on a `list` has no side effects
(versus some other things, where it is not the case).

Linters are the best place for this: they warn about probably-mistakes
idioms like this, and can have slightly deep knowledge of the code's
semantics sometimes.

>If I submit a suggestion to python-list@python.org will it just show
>up here? Or do the actual Python devs intercept it?

Nah, it'll go through.

Cheers,
Cameron Simpson <cs@cskk.id.au>

Pages:12
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor