diff mbox series

[12/14] size-stats-compare: fix code style

Message ID 1516581882-30582-13-git-send-email-ricardo.martincoski@gmail.com
State Superseded
Headers show
Series fix Python code style | expand

Commit Message

Ricardo Martincoski Jan. 22, 2018, 12:44 a.m. UTC
Fix these warnings:
E129 visually indented line with same indent as next logical line
E302 expected 2 blank lines, found 1

Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Cc: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 utils/size-stats-compare | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Thomas Petazzoni Jan. 29, 2018, 10:13 p.m. UTC | #1
Hello,

On Sun, 21 Jan 2018 22:44:40 -0200, Ricardo Martincoski wrote:
> Fix these warnings:
> E129 visually indented line with same indent as next logical line

Really?

>      header = next(reader)
>      if (header[0] != 'File name' or header[1] != 'Package name' or
> -        header[2] != 'File size' or header[3] != 'Package size'):
> +            header[2] != 'File size' or header[3] != 'Package size'):

This looks totally bogus to me. The code was properly and nicely
indented before the change, and now it looks badly indented. Is this
really what flake8 wants? If so, flake8 is very strange.

Thomas
Yann E. MORIN Feb. 3, 2018, 3:24 p.m. UTC | #2
Thomas, Ricardo, All,

On 2018-01-29 23:13 +0100, Thomas Petazzoni spake thusly:
> On Sun, 21 Jan 2018 22:44:40 -0200, Ricardo Martincoski wrote:
> > Fix these warnings:
> > E129 visually indented line with same indent as next logical line
> 
> Really?
> 
> >      header = next(reader)
> >      if (header[0] != 'File name' or header[1] != 'Package name' or
> > -        header[2] != 'File size' or header[3] != 'Package size'):
> > +            header[2] != 'File size' or header[3] != 'Package size'):
> 
> This looks totally bogus to me. The code was properly and nicely
> indented before the change, and now it looks badly indented. Is this
> really what flake8 wants? If so, flake8 is very strange.

I guess it 's probably more about the following line than about hte
previous one:

    if (header[0] != 'File name' or header[1] != 'Package name' or
        header[2] != 'File size' or header[3] != 'Package size'):
        print(("Input file %s does not contain the expected header. Are you "

... where there could be confusion with the 'printf' line.

Maybe the printf line could be indented one-level mnore, instead? Nope,
that does not solve the issue. I guess flake8 does not do look-ahead...

In this case, I would be happy with an exception...  # noqa E129

Regards,
Yann E. MORIN.
Ricardo Martincoski Feb. 13, 2018, 3:28 a.m. UTC | #3
Hello,

On Sat, Feb 03, 2018 at 01:24 PM, Yann E. MORIN wrote:

> On 2018-01-29 23:13 +0100, Thomas Petazzoni spake thusly:
>> On Sun, 21 Jan 2018 22:44:40 -0200, Ricardo Martincoski wrote:
>> > Fix these warnings:
>> > E129 visually indented line with same indent as next logical line
>> 
>> Really?
>> 
>> >      header = next(reader)
>> >      if (header[0] != 'File name' or header[1] != 'Package name' or
>> > -        header[2] != 'File size' or header[3] != 'Package size'):
>> > +            header[2] != 'File size' or header[3] != 'Package size'):
>> 
>> This looks totally bogus to me. The code was properly and nicely
>> indented before the change, and now it looks badly indented. Is this
>> really what flake8 wants? If so, flake8 is very strange.

Sorry. I failed to explore all possible acceptable formats, see below...

> 
> I guess it 's probably more about the following line than about hte
> previous one:
> 
>     if (header[0] != 'File name' or header[1] != 'Package name' or
>         header[2] != 'File size' or header[3] != 'Package size'):
>         print(("Input file %s does not contain the expected header. Are you "
> 
> ... where there could be confusion with the 'printf' line.

Yes. I think that's it.

> 
> Maybe the printf line could be indented one-level mnore, instead? Nope,
> that does not solve the issue. I guess flake8 does not do look-ahead...

Maybe one of these?

This I think it is uglier:

    if (
            header[0] != 'File name' or header[1] != 'Package name' or
            header[2] != 'File size' or header[3] != 'Package size'):
        print(("Input file %s does not contain the expected header. Are you "

... This is present in other scripts and I missed that in v1. I plan to use it
if you don't oppose to.

    if header[0] != 'File name' or header[1] != 'Package name' or \
       header[2] != 'File size' or header[3] != 'Package size':
        print(("Input file %s does not contain the expected header. Are you "

> 
> In this case, I would be happy with an exception...  # noqa E129

If we don't agree with this rule, perhaps is better to ignore it for any new
script, by adding this line to .flake8:
ignore=E129

Regards,
Ricardo
Thomas Petazzoni Feb. 13, 2018, 7:51 a.m. UTC | #4
Hello,

On Tue, 13 Feb 2018 01:28:31 -0200, Ricardo Martincoski wrote:

> ... This is present in other scripts and I missed that in v1. I plan to use it
> if you don't oppose to.
> 
>     if header[0] != 'File name' or header[1] != 'Package name' or \
>        header[2] != 'File size' or header[3] != 'Package size':
>         print(("Input file %s does not contain the expected header. Are you "

This version looks good to me. The parenthesis around the if condition
are useless in Python.

Thomas
Thomas De Schampheleire Feb. 13, 2018, 8:53 p.m. UTC | #5
On Tue, Feb 13, 2018 at 08:51:34AM +0100, Thomas Petazzoni wrote:
> Hello,
> 
> On Tue, 13 Feb 2018 01:28:31 -0200, Ricardo Martincoski wrote:
> 
> > ... This is present in other scripts and I missed that in v1. I plan to use it
> > if you don't oppose to.
> > 
> >     if header[0] != 'File name' or header[1] != 'Package name' or \
> >        header[2] != 'File size' or header[3] != 'Package size':
> >         print(("Input file %s does not contain the expected header. Are you "
> 
> This version looks good to me. The parenthesis around the if condition
> are useless in Python.

That is not completely accurate: the parentheses are not needed for the if, they
are an alternative to providing a line-continuation character. I.e.

    if (expression1 or
        expression2):

is equivalent to:

    if expression1 or \
       expression2:

Some people/groups prefer to avoid line continuation characters by using the
parentheses style.

/Thomas
diff mbox series

Patch

diff --git a/utils/size-stats-compare b/utils/size-stats-compare
index e5a1ec3..f69c3ed 100755
--- a/utils/size-stats-compare
+++ b/utils/size-stats-compare
@@ -24,6 +24,7 @@  import csv
 import argparse
 import sys
 
+
 def read_file_size_csv(inputf, detail=None):
     """Extract package or file sizes from CSV file into size dictionary"""
     sizes = {}
@@ -31,7 +32,7 @@  def read_file_size_csv(inputf, detail=None):
 
     header = next(reader)
     if (header[0] != 'File name' or header[1] != 'Package name' or
-        header[2] != 'File size' or header[3] != 'Package size'):
+            header[2] != 'File size' or header[3] != 'Package size'):
         print(("Input file %s does not contain the expected header. Are you "
                "sure this file corresponds to the file-size-stats.csv "
                "file created by 'make graph-size'?") % inputf.name)
@@ -45,6 +46,7 @@  def read_file_size_csv(inputf, detail=None):
 
     return sizes
 
+
 def compare_sizes(old, new):
     """Return delta/added/removed dictionaries based on two input size
     dictionaries"""
@@ -64,6 +66,7 @@  def compare_sizes(old, new):
 
     return delta
 
+
 def print_results(result, threshold):
     """Print the given result dictionary sorted by size, ignoring any entries
     below or equal to threshold"""