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

Cameron Simpson cs at cskk.id.au
Tue Nov 15 04:13:04 EST 2022


On 15Nov2022 00:45, avi.e.gross at gmail.com <avi.e.gross at 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 the OP's issue is that 
the bare `x.clear` is evaluated but not stored in a variable. As a 
metric, we might gather various descriptive statements we could make 
about these statements. They'd perhaps include "is legal Python code", 
"is pretty simple". The former line could include "saves the expression 
value in a variable for later use" and the latter could not. That's a 
comparison test you could use for ordering.

My own opinion is that a bare:

     x.clear

is legal and valid for all the example use cases already mentioned, but 
an entirely valid target for complaint by a linter, whose task is to 
point out dodgy looking stuff for review by the author.

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


More information about the Python-list mailing list