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

2022-11-25 Thread Dan Stromberg
On Sun, Nov 13, 2022 at 4:45 PM DFS wrote: > In code, list.clear is just ignored. > At the terminal, list.clear shows > > > > in code: > x = [1,2,3] > x.clear > print(len(x)) > 3 > > at terminal: > x = [1,2,3] > x.clear > > print(len(x)) > 3 > > > Caused me an hour of frustration before I notic

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

2022-11-23 Thread Chris Angelico
On Thu, 24 Nov 2022 at 06:26, Stefan Ram wrote: > > Jon Ribbens writes: > >If you want to catch this sort of mistake automatically then you need > >a linter such as pylint: > > output > > , line 1 > list.clear > Warning: Attribute used as statement. > > , line 5 > list.clear > Warning: Attribut

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

2022-11-15 Thread avi.e.gross
: Python-list On Behalf Of Chris Angelico Sent: Tuesday, November 15, 2022 6:16 PM To: python-list@python.org Subject: Re: In code, list.clear doesn't throw error - it's just ignored On Wed, 16 Nov 2022 at 10:11, wrote: > > That is clear, Cameron, but on my python interpreter values

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

2022-11-15 Thread Chris Angelico
On Wed, 16 Nov 2022 at 10:11, wrote: > > That is clear, Cameron, but on my python interpreter values evaluated on the > command line ARE saved: > > >>> numb = 5 > >>> 5 + numb > 10 > >>> numb > 5 > >>> _ + _ + 1 > 11 That's a REPL feature. ChrisA -- https://mail.python.org/mailman/listinfo/pyth

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

2022-11-15 Thread avi.e.gross
I grant generally a naked evaluation is generally an error. LOL! -Original Message- From: Python-list On Behalf Of Cameron Simpson Sent: Tuesday, November 15, 2022 4:13 AM To: python-list@python.org Subject: Re: In code, list.clear doesn't throw error - it's just ignored On 15Nov

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

2022-11-15 Thread Cameron Simpson
On 15Nov2022 00:45, avi.e.gr...@gmail.com wrote: What would be the meaning of an ordering relation determining what is MORE VALID? Are you asking what criterion would rate: clearx = x.clear as "more" valid than: x.clear on its own? I don't want to speak for the OP, but I'd think t

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

2022-11-14 Thread avi.e.gross
22 9:34 PM To: python-list@python.org Subject: Re: In code, list.clear doesn't throw error - it's just ignored On 14Nov2022 19:15, Dennis Lee Bieber wrote: > There is also the minor facet that "x.clear" can be bound to a >different name... > >>>&g

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

2022-11-14 Thread Cameron Simpson
On 14Nov2022 19:15, Dennis Lee Bieber wrote: There is also the minor facet that "x.clear" can be bound to a different name... x = [1, 2, 3.145926536, "Pie"] clearx = x.clear x [1, 2, 3.145926536, 'Pie'] clearx() x [] I think the OP would take the stance that this: clearx =

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

2022-11-14 Thread Dennis Lee Bieber
On Tue, 15 Nov 2022 09:11:10 +1100, Cameron Simpson declaimed the following: >On 13Nov2022 22:23, DFS wrote: >>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 embeddin

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

2022-11-14 Thread Cameron Simpson
On 13Nov2022 22:23, DFS 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, b

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

2022-11-14 Thread Chris Angelico
On Tue, 15 Nov 2022 at 05:57, Stefan Ram wrote: > > Michael Speer 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

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

2022-11-14 Thread Jon Ribbens via Python-list
On 2022-11-14, Stefan Ram wrote: > Jon Ribbens 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, lin

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

2022-11-14 Thread Weatherby,Gerard
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

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

2022-11-14 Thread Karsten Hilbert
Am Mon, Nov 14, 2022 at 02:13:34AM + 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 7D4

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

2022-11-14 Thread Roel Schroeven
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 wrote: On 11/13/2022 5:20 PM, Jon Ribbens wrote: On 2022-11-13, DFS wrote: In code, list.clear is just ignored. At the terminal, list.clear shows in code: x = [1,2,3] x.clea

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

2022-11-13 Thread dn
On 14/11/2022 12.12, DFS wrote: On 11/13/2022 5:20 PM, Jon Ribbens wrote: On 2022-11-13, DFS wrote: In code, list.clear is just ignored. At the terminal, list.clear shows in code: x = [1,2,3] x.clear print(len(x)) 3 at terminal: x = [1,2,3] x.clear print(len(x)) 3 Caused me an hour of f

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

2022-11-13 Thread Chris Angelico
On Mon, 14 Nov 2022 at 18:00, Greg Ewing 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

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

2022-11-13 Thread Greg Ewing
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

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

2022-11-13 Thread Michael Speer
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

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

2022-11-13 Thread DFS
On 11/13/2022 9:11 PM, Chris Angelico wrote: On Mon, 14 Nov 2022 at 11:53, DFS wrote: On 11/13/2022 5:20 PM, Jon Ribbens wrote: On 2022-11-13, DFS wrote: In code, list.clear is just ignored. At the terminal, list.clear shows in code: x = [1,2,3] x.clear print(len(x)) 3 at terminal: x =

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

2022-11-13 Thread Jon Ribbens via Python-list
On 2022-11-14, Greg Ewing wrote: > On 14/11/22 1:31 pm, Jon Ribbens wrote: >> On 2022-11-13, DFS 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 exp

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

2022-11-13 Thread Chris Angelico
On Mon, 14 Nov 2022 at 13:18, MRAB 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 wrote: > >>> 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

2022-11-13 Thread MRAB
On 2022-11-14 00:55, Greg Ewing wrote: On 14/11/22 1:31 pm, Jon Ribbens wrote: On 2022-11-13, DFS 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 a

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

2022-11-13 Thread Chris Angelico
On Mon, 14 Nov 2022 at 11:53, DFS wrote: > > On 11/13/2022 5:20 PM, Jon Ribbens wrote: > > On 2022-11-13, DFS wrote: > >> In code, list.clear is just ignored. > >> At the terminal, list.clear shows > >> > >> > >> > >> in code: > >> x = [1,2,3] > >> x.clear > >> print(len(x)) > >> 3 > >> > >> at

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

2022-11-13 Thread Greg Ewing
On 14/11/22 1:31 pm, Jon Ribbens wrote: On 2022-11-13, DFS 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 -- https

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

2022-11-13 Thread Jon Ribbens via Python-list
On 2022-11-13, DFS wrote: > On 11/13/2022 5:20 PM, Jon Ribbens wrote: >> On 2022-11-13, DFS wrote: >>> In code, list.clear is just ignored. >>> At the terminal, list.clear shows >>> >>> >>> >>> in code: >>> x = [1,2,3] >>> x.clear >>> print(len(x)) >>> 3 >>> >>> at terminal: >>> x = [1,2,3] >>>

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

2022-11-13 Thread DFS
On 11/13/2022 5:20 PM, Jon Ribbens wrote: On 2022-11-13, DFS wrote: In code, list.clear is just ignored. At the terminal, list.clear shows in code: x = [1,2,3] x.clear print(len(x)) 3 at terminal: x = [1,2,3] x.clear print(len(x)) 3 Caused me an hour of frustration before I noticed list.

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

2022-11-13 Thread Jon Ribbens via Python-list
On 2022-11-13, DFS wrote: > In code, list.clear is just ignored. > At the terminal, list.clear shows > > > > in code: > x = [1,2,3] > x.clear > print(len(x)) > 3 > > at terminal: > x = [1,2,3] > x.clear > > print(len(x)) > 3 > > > Caused me an hour of frustration before I noticed list.clear() was