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
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)
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?
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.
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!
1
1 + 2
print(1 + 2)
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.
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.
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.
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.
But if it's an expression where it's expecting a statement and it's not
a call, then it's probably a bug.
On 11/13/2022 9:11 PM, Chris Angelico wrote:
On Mon, 14 Nov 2022 at 11:53, DFS <nospam@dfs.com> wrote:what
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
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
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.
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.It looks 'right' because it is 'right'!
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!
Python doesn't care what an expression returns.
If you want to catch this sort of mistake automatically then you need
a linter such as pylint:
Because it's an expression, and you're allowed to execute expressions.
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:But why is it allowed in the first place?
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
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.
<built-in method clear of list object at 0x000002947DBBF680>x = [1, 2, 3]
x.clear
But if it's an expression where it's expecting a statement and it's not a call, then
it's probably a bug.
"""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.
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.
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.
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.
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?
On 13Nov2022 22:23, DFS <nospam@dfs.com> 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 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).
[1, 2, 3.145926536, 'Pie']x = [1, 2, 3.145926536, "Pie"]
clearx = x.clear
x
[]clearx()
x
There is also the minor facet that "x.clear" can be bound to a
different name...
[1, 2, 3.145926536, 'Pie']x = [1, 2, 3.145926536, "Pie"]
clearx = x.clear
x
[]clearx()
x
There is also the minor facet that "x.clear" can be bound to a
different name...
[1, 2, 3.145926536, 'Pie']x = [1, 2, 3.145926536, "Pie"]
clearx = x.clear
x
[]clearx()
x
What would be the meaning of an ordering relation determining what is
MORE VALID?
10numb = 5
5 + numb
5numb
11_ + _ + 1
22_ * 2
What would be the meaning of an ordering relation determining what is
MORE VALID?
That is clear, Cameron, but on my python interpreter values evaluated on the command line ARE saved:
10numb = 5
5 + numb
5numb
11_ + _ + 1
That is clear, Cameron, but on my python interpreter values evaluated
on the command line ARE saved:
10numb = 5
5 + numb
5numb
11_ + _ + 1
In VBA, "debug.print" is allowed, having the same meaning as
"debug.print()", while "sin" gives an error: "Argument is not
optional".
If you want to catch this sort of mistake automatically then you need
a linter such as pylint:
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:
output
<string>, line 1
list.clear
Warning: Attribute used as statement.
<string>, line 5
list.clear
Warning: Attribute used as statement.
source code
import ast, sys
def check( point, source ):
if isinstance( point, ast.Expr ) and\
type( point.value )== ast.Attribute:
print( "<string>, line", point.lineno, file=sys.stderr )
print( source.split( '\n' )[ point.lineno-1 ], file=sys.stderr )
print\
( "Warning:", "Attribute used as statement.", file=sys.stderr )
print()
def mylinter( source ):
for point in ast.walk( ast.parse( example )):
check( point, source )
example = """\
list.clear
list.clear()
x = list.clear
print( list.clear )
list.clear
"""
mylinter( example )
In code, list.clear is just ignored.
At the terminal, list.clear shows <built-in method clear of list object
at 0x000001C9CFEC4240>
l=[1,2,3]
help(l.clear)
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://mail.python.org/mailman/listinfo/python-list
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 58:18:03 |
Calls: | 6,712 |
Files: | 12,243 |
Messages: | 5,355,631 |