Rev 842c214 merges no-else-return branch into devel

37 views
Skip to first unread message

Edward K. Ream

unread,
Jun 6, 2019, 1:10:58 PM6/6/19
to leo-editor
This removes all no-else-return complaints from pylint. As mentioned earlier, all these changes could cause problems, but we aren't going back.

In addition to style changes, the new code contains two substantial improvements:

1. Fixed an ancient, serious, bug in Leo's BackgroundProcessManager class. This bug made it impossible to run pylint on more than one file and do anything useful with the supposedly "live" links.  All the links referred to the first file containing any pylint errors!

2. Improved the regex describing pylint error messages.  This regex is now defined at the start of the PylintCommand class.  It's more general (allowing all forms of file names) and more specific (highly unlikely to match anything other than a real pylint message).

Please report all new problem immediately. Thanks.

Edward

Edward K. Ream

unread,
Jun 6, 2019, 2:11:36 PM6/6/19
to leo-editor
On Thursday, June 6, 2019 at 12:10:58 PM UTC-5, Edward K. Ream wrote:

> This removes all no-else-return complaints from pylint.

My first reaction to this check was "huh?"  But the more I see the changes the better I like them:

- Flow of control is often easier to understand.
- The new style often results in less indented code and fewer "else" statements.

While making all these changes, I fixed some howlers:

if condition:
 
return True
else:
 
return False

Should be:

return condition

Similarly:

if condition:
 
return val1
else
 
return val2

can be replaced (if condition isn't too long) by:

return val1 if condition else val2

And worse:

if not condition:
 
return val1
else
 
return val2

should be:

return val2 if condition else val1

All such replacements are opportunities for blunders, so one must take care!

Edward

Edward K. Ream

unread,
Jun 6, 2019, 2:16:15 PM6/6/19
to leo-editor

On Thursday, June 6, 2019 at 12:10:58 PM UTC-5, Edward K. Ream wrote:

> This removes all no-else-return complaints from pylint.

Let me emphasize the most important part of all this pylint-related work.  Pylint does (usually) suggest real stylistic improvements, but the reason I am doing the work is simply to put these matters behind me.  This, and only this, is the reason I have spent a day or two on pylint.  Understand?

More generally, I have been telling people that I have been "on fire" with Leo.  The reason for all this energy is that I am making sure to complete, as much as possible, each item.  It's an energy drain to leave unfinished stuff lying around. I don't do that any more.

Edward


Edward K. Ream

unread,
Jun 6, 2019, 6:00:31 PM6/6/19
to leo-editor
On Thursday, June 6, 2019 at 1:16:15 PM UTC-5, Edward K. Ream wrote:

Let me emphasize the most important part of all this pylint-related work.  Pylint does (usually) suggest real stylistic improvements, but the reason I am doing the work is simply to put these matters behind me.  This, and only this, is the reason I have spent a day or two on pylint.  Understand?

A milestone.  The pylint work is now complete, with just a few more changes.

leo/test/pylint-leo-rc-ref.txt contains the pylint args that I prefer.  This file suppresses a minimum of pylint tests.  It gives my reasons for several of the suppressions.

It is now a snap to fix pylint problems using the clickable links in the log pane.  A belated thanks for Terry for doing this.  It's so so useful.

Edward
Reply all
Reply to author
Forward
0 new messages