Mass formatting updates to Leo's core and plugins

41 views
Skip to first unread message

Edward K. Ream

unread,
May 19, 2016, 10:54:32 AM5/19/16
to leo-editor
Warning: all plugin authors should check their plugins. Recent revs have changed many (most) plugins.  I have been as careful as I can, but there are no guarantees.

Recent revs have fixed the following:

1. all pylint, pyflakes and flake8 complaints in Leo's core,
2. all pylint and pyflakes complaints in Leo's plugins.

Still to do: fix flake8 complaints in plugins.

Yes, innocent-looking changes can create problems.  I have been running all tests before upping the code.  Such mucking about should be done early in the release cycle.

Still, the recent changes have been worthwhile.  A number of buglets have been revealed and fixed. Even the cosmetic changes are reasonable. I have disabled all the flake8 checks that seem overly picky, and that includes almost all checks for whitespace around operators and whitespace in continued lines.

It's funny, really.  Pep 8 (and many people) seem to be obsessed with whitespace in continued lines, the very places where indentation makes absolutely no difference to the python parser!

My attitude is this: if you want to improve whitespace, use Leo's beautification commands.

In fact, there were only a few kinds of fixes required:

E101: indentation contains mixed spaces and tabs
E111: indentation is not a multiple of four
E129: visually indented line with same indent as next logical line
W293: blank line contains whitespace
E501: line too long (over 120 characters)
E711: comparison to None should be ‘if cond is None:’
E712: comparison to True should be ‘if cond is True:’ or ‘if cond:’
E713: test for membership should be ‘not in’
E714: test for object identity should be ‘is not’

Important: E711 can be serious. Comparing positions to None is always a bug, except for low-level code.  The proper tests are "if p:" or "if not p".

An example of E129:

if (a long test
    continued on the
next line):
    first line of block

should be:

if (a long test
    continued on the
next line
):
    first line of block

Similarly:

def foo (lots of args,
    continued on
next line):
    first line of block

should be:

def foo (lots of args,
    continued on
next line
):
    first line of block

To summarize: the recent changes aren't much about whitespace and indentation. The few stylistic changes that have been made seem worth the risk of making them.

We won't debate style issues here: you can always change your flake8 config file.

All comments welcome.

Edward

Edward K. Ream

unread,
May 19, 2016, 11:12:00 AM5/19/16
to leo-editor
On Thursday, May 19, 2016 at 9:54:32 AM UTC-5, Edward K. Ream wrote:

In fact, there were only a few kinds of fixes required:

E101: indentation contains mixed spaces and tabs
E111: indentation is not a multiple of four
E129: visually indented line with same indent as next logical line
W293: blank line contains whitespace
E501: line too long (over 120 characters)
E711: comparison to None should be ‘if cond is None:’
E712: comparison to True should be ‘if cond is True:’ or ‘if cond:’
E713: test for membership should be ‘not in’
E714: test for object identity should be ‘is not’

I forgot to mention this one:

W503 (*) line break occurred before a binary operator

For example:

if ( a
   
and b
   
or c
):

would better be:

if (a and
    b
or
    c
):

This contrived example doesn't capture the improvement for complex conditionals.

I did take the opportunity, mostly in some ancient code of mine, to split complex conditionals to multiple lines.  In some cases, I could see hints of my ancient C coding style...

I'll apply any flake8 changes to plugins in the next day or so.  After that, I'll leave well enough alone.

EKR

Edward K. Ream

unread,
May 19, 2016, 11:17:33 AM5/19/16
to leo-editor
On Thursday, May 19, 2016 at 9:54:32 AM UTC-5, Edward K. Ream wrote:

Recent revs have fixed the following:

1. all pylint, pyflakes and flake8 complaints in Leo's core,
2. all pylint and pyflakes complaints in Leo's plugins.

Still to do: fix flake8 complaints in plugins.

There has been another benefit of all this: finding "missing" plugins that are not found in leoPluginsRef.leo.  I've already added several @file nodes to leoPluginsRef.leo, and it looks like one or two more will be added soon.

EKR
Reply all
Reply to author
Forward
0 new messages