#973 closed defect (fixed)

Fix warnings found by pylint

Reported by: davidsarah Owned by: davidsarah
Priority: minor Milestone: 1.7.0
Component: code Version: 1.6.0
Keywords: pylint cleanup reviewed Cc:
Launchpad Bug:

Description

I tried running pylint on the Tahoe source. It produced a lot of false alarms, but some things that are worth fixing. The HTML output, and an initial patch to fix some indentation errors are attached.

Attachments (9)

pylint.html (698.3 KB) - added by davidsarah at 2010-02-26T05:36:40Z.
output of pylint --rcfile=tahoe.pylintrc allmydata
tahoe.pylintrc (9.2 KB) - added by davidsarah at 2010-02-26T05:37:56Z.
pylint configuration file to reduce obvious false-positives
correct-indentation-darcspatch.txt (59.4 KB) - added by davidsarah at 2010-02-26T05:38:44Z.
Correct harmless indentation errors found by pylint
change-imports-to-absolute-darcspatch.txt (68.2 KB) - added by davidsarah at 2010-02-26T07:36:51Z.
Change relative imports to absolute. Relative imports are ambiguous and will not be supported with the current syntax in Python 2.7.
FORMAT-checked-output.html (36.0 KB) - added by writefaruq at 2010-05-07T20:52:47Z.
FORMAT-checked-output.txt (15.6 KB) - added by writefaruq at 2010-05-07T20:55:45Z.
After applying "correct-indentation-darcspatch.txt" patch to current source and then running pylint FORMAT checker
scrot.png (276.0 KB) - added by zooko at 2010-05-08T05:01:21Z.
FORMAT-checked-output.2.txt (3.5 KB) - added by writefaruq at 2010-05-08T20:52:14Z.
Ignoring C0301, C0321
IMPORTS-checked-output-2.txt (46.5 KB) - added by writefaruq at 2010-05-08T21:44:50Z.
Reports import failed: F0401(128 times), deprecated module: W0402(2), Reimport:W0404(3), self import:W0406(1)

Download all attachments as: .zip

Change History (23)

Changed at 2010-02-26T05:36:40Z by davidsarah

output of pylint --rcfile=tahoe.pylintrc allmydata

Changed at 2010-02-26T05:37:56Z by davidsarah

pylint configuration file to reduce obvious false-positives

Changed at 2010-02-26T05:38:44Z by davidsarah

Correct harmless indentation errors found by pylint

comment:1 Changed at 2010-02-26T05:40:07Z by davidsarah

  • Keywords review-needed added

Changed at 2010-02-26T07:36:51Z by davidsarah

Change relative imports to absolute. Relative imports are ambiguous and will not be supported with the current syntax in Python 2.7.

comment:2 Changed at 2010-02-26T08:04:51Z by davidsarah

Well, [apparently http://old.nabble.com/Absolute-imports-in-Python-2.x--td27419560.html] removal of support for relative imports didn't happen, but they're a bad idea anyway.

comment:3 Changed at 2010-05-05T19:47:50Z by writefaruq

  • Owner changed from somebody to writefaruq
  • Status changed from new to assigned

Changed at 2010-05-07T20:52:47Z by writefaruq

comment:4 Changed at 2010-05-07T20:53:28Z by writefaruq

After applying "correct-indentation-darcspatch.txt" patch to current source and then running pylint FORMAT checker I got a few warnings.

Changed at 2010-05-07T20:55:45Z by writefaruq

After applying "correct-indentation-darcspatch.txt" patch to current source and then running pylint FORMAT checker

Changed at 2010-05-08T05:01:21Z by zooko

comment:5 follow-up: Changed at 2010-05-08T05:06:58Z by zooko

Dear Faruq:

Blah, I just scanned through FORMAT-checked-output.txt and I'm not impressed with pylint. All the notes I saw were "line too long" and "multiple statements on a single line". Most but not all were pointing at code that I wrote. My assumption is that the lines in question are better written the way they are and we should stop running pylint and ban it from our project. Note that our coding standards explicitly reject the convention of limiting lines to 72- or 79- chars.

Okay, okay, I'll look closer.

Here's the first "line too long" that I looked at: check_results.py line 21.

    def set_healthy(self, healthy):
        self.healthy = bool(healthy)
        if self.healthy:
            assert (not hasattr(self, 'recoverable')) or self.recoverable, hasattr(self, 'recoverable') and self.recoverable
            self.recoverable = True
            self.summary = "healthy"
        else:
            self.summary = "not healthy"

Attached as "scrot.png" is a screenshot of what this method looks like in my emacs side by side with what it looks like after being line-wrapped. I prefer the unwrapped version! Note that my emacs automatically line-wraps the line that extends past the width of the frame but (unfortunately) does not indent the continuation. I prefer this style: let carriage returns signify logical breaks, i.e. the ends of statements, and let your tools (trac, emacs, vi, screen, your terminal emulator) do formatting for visual purposes. For example, this makes "grep" tell me what I want to know:

HACK Wonwin-McBrootles-Computer:~/playground/tahoe-lafs/trunk/pristine$ grep assert src/allmydata/check_results.py
        assert IURI.providedBy(uri), uri
            assert (not hasattr(self, 'recoverable')) or self.recoverable, hasattr(self, 'recoverable') and self.recoverable
            assert (not hasattr(self, 'healthy')) or not self.healthy
        assert isinstance(summary, str) # should be a single string
        assert not isinstance(report, str) # should be list of strings
        assert isinstance(path, (list, tuple))
        assert isinstance(path, (list, tuple))

Where with the line-wrapping grep is now giving me an incomplete answer about that line:

HACK Wonwin-McBrootles-Computer:~/playground/tahoe-lafs/trunk/pristine$ grep assert src/allmydata/check_results-pylinted.py
        assert IURI.providedBy(uri), uri
            assert (not hasattr(self, 'recoverable')) or
            assert (not hasattr(self, 'healthy')) or not self.healthy
        assert isinstance(summary, str) # should be a single string
        assert not isinstance(report, str) # should be list of strings
        assert isinstance(path, (list, tuple))
        assert isinstance(path, (list, tuple))

Okay, so let's ignore, at least for now, all instances of C0301 "line too long" and C0321 "More than one statement on a single line". In fact, let's add those two to the list of "disable-msg" in http://tahoe-lafs.org/trac/tahoe-lafs/attachment/ticket/973/tahoe.pylintrc and let's add that pylintrc file into our source repo (somewhere) for other people to use).

And then, please read through David-Sarah's patches correct-indentation-darcspatch.txt and change-imports-to-absolute-darcspatch.txt and see if there are any mistakes in it. :-)

Thanks!

Changed at 2010-05-08T20:52:14Z by writefaruq

Ignoring C0301, C0321

Changed at 2010-05-08T21:44:50Z by writefaruq

Reports import failed: F0401(128 times), deprecated module: W0402(2), Reimport:W0404(3), self import:W0406(1)

comment:6 Changed at 2010-05-08T21:49:42Z by writefaruq

  • Owner changed from writefaruq to davidsarah
  • Status changed from assigned to new

Need to see why so many import fails. Is this a false alarm or feature of pylint ? I'm happy with all else

comment:7 follow-up: Changed at 2010-05-08T22:33:20Z by zooko

Well, those are imports of external libraries, and I guess maybe you don't have them installed. For example, the first one is

F0401: 26: Unable to import 'nevow'

Do you have the "nevow" package installed? Here is a good way to tell:

python -c 'import pkg_resources;print pkg_resources.require("nevow")'

comment:8 Changed at 2010-05-08T22:33:39Z by zooko

  • Owner changed from davidsarah to writefaruq

comment:9 in reply to: ↑ 5 Changed at 2010-05-08T22:47:55Z by davidsarah

Replying to zooko:

Blah, I just scanned through FORMAT-checked-output.txt and I'm not impressed with pylint.

Well, that's just the formatting checker, which is one of the least interesting. The maximum line length is configured at 120 (here), and personally I think that is too long in most cases.

Here's the first "line too long" that I looked at: check_results.py line 21.

    def set_healthy(self, healthy):
        self.healthy = bool(healthy)
        if self.healthy:
            assert (not hasattr(self, 'recoverable')) or self.recoverable, hasattr(self, 'recoverable') and self.recoverable
            self.recoverable = True
            self.summary = "healthy"
        else:
            self.summary = "not healthy"

Attached as "scrot.png" is a screenshot of what this method looks like in my emacs side by side with what it looks like after being line-wrapped. I prefer the unwrapped version!

That's because you wrapped it at 65 characters, if I'm counting correctly. It looks much better (and would not have any problems with grepping for subexpressions) when wrapped at the comma, which is still well below 120 characters.

I'm not suggesting that we should spend a lot (or any) effort on fixing minor formatting issues like this, though.

comment:10 in reply to: ↑ 7 Changed at 2010-05-09T21:36:09Z by writefaruq

Replying to zooko:

Well, those are imports of external libraries, and I guess maybe you don't have them installed. For example, the first one is

F0401: 26: Unable to import 'nevow'

Do you have the "nevow" package installed? Here is a good way to tell:

python -c 'import pkg_resources;print pkg_resources.require("nevow")'

Yes, that's right. I installed a few of those libraries and these messages vanished. :)

comment:11 Changed at 2010-05-14T19:33:16Z by zooko

faruq: if you could configure the tahoe.pylintrc to exclude C0301, C0321 and then put the .pylintrc file into misc and run darcs add misc/tahoe.pylintrc and darcs record then we can get that configuration file into our source tree.

comment:12 Changed at 2010-05-19T17:16:44Z by writefaruq

  • Keywords reviewed added; review-needed removed
  • Owner changed from writefaruq to davidsarah

comment:13 Changed at 2010-05-20T04:35:45Z by davidsarah

  • Status changed from new to assigned

comment:14 Changed at 2010-06-08T04:44:15Z by davidsarah

  • Resolution set to fixed
  • Status changed from assigned to closed
Note: See TracTickets for help on using tickets.