FYI: pylint-leo-rc-ref.txt disables two new pylint tests

25 views
Skip to first unread message

Edward K. Ream

unread,
Apr 1, 2020, 9:40:08 AM4/1/20
to leo-editor
leo/test/pylint-leo-rc-ref.txt now disables the following two new tests:

    no-elif-break
    no-else-break

Imo, these are just plain wrong. Following the pylint advice would change the meaning of the program. These look like serious pylint bugs.

Edward

vitalije

unread,
Apr 1, 2020, 9:52:27 AM4/1/20
to leo-editor
I doubt that. A few days ago I've run pylint and it reported some complains about non necessary else after break, or after return. My first reaction was just like yours, but then I looked more closely and those complains were correct.

while True:
   
... # some code here
   
if condition:
         
break
   
else:
         do_something_else_here
()

# or
def f():
   
# some code ...
   
if condition:
       
return result_a
   
else:
        do_other_thing
()
       
# ...
       
return result_b


 In both cases, meaning of the program is the same as if the else block was unindented and else removed.

Vitalije

Edward K. Ream

unread,
Apr 1, 2020, 10:43:27 AM4/1/20
to leo-editor
The test is valid in the cases you give. However, the test is invalid if the break is within an 'if' statement. It's a botch.

Edward

Thomas Passin

unread,
Apr 1, 2020, 10:45:21 AM4/1/20
to leo-editor
It's really a comprehension vs brevity thing, and a matter of personal style.  Removing the else gives shorter code, which is usually more clear.  But without the else, you have to infer its virtual presence, and that interferes with comprehension.  I'm not consistent about this, myself.  But functionally, sure, both forms are the same.

Edward K. Ream

unread,
Apr 1, 2020, 11:07:36 AM4/1/20
to leo-editor
On Wed, Apr 1, 2020 at 9:45 AM Thomas Passin <tbp1...@gmail.com> wrote:
It's really a comprehension vs brevity thing, and a matter of personal style. 

No. It's a pylint bug. Enable the two checks and look at the warnings.

Edward
Reply all
Reply to author
Forward
0 new messages