Repository navigation
Conversation
This is a known false positive in flake8, if and when we adopt black for all of Biopython we would adopt the black convention here (and ignore E203 if this problem persists)
|
One of the things I love about |
|
I suppose by discarding any idiosyncratic personal style quirks (in line breaking etc), it makes the code more standard, and thus leaves a better impression? Or maybe you just like the black style more than your style from ten years back ;) |
|
😂I like the black style more than my style, now! |
Codecov Report
@@ Coverage Diff @@
## master #2079 +/- ##
=========================================
+ Coverage 83.56% 84.87% +1.3%
=========================================
Files 317 318 +1
Lines 50834 50884 +50
=========================================
+ Hits 42480 43187 +707
+ Misses 8354 7697 -657
Continue to review full report at Codecov.
|
|
Wow, this looks even worse than I have feared... Even if it's not breaking PEP8 literally, I have the feeling it's breaking the spirit of PEP8. It looks so un-pythonic. In this examples, you probably want to keep the x,y values in the point lists on one line? |
|
I disagree with that it's breaking the spirit of PEP8 or that it is un-pythonic - but it is different and seems to generate polarising views. Quoting a specific example from def __init__(self, parent, pagesize='A3', orientation='landscape',
x=0.05, y=0.05, xl=None, xr=None, yt=None, yb=None,
start=None, end=None, tracklines=0, cross_track_links=None):after black: def __init__(
self,
parent,
pagesize="A3",
orientation="landscape",
x=0.05,
y=0.05,
xl=None,
xr=None,
yt=None,
yb=None,
start=None,
end=None,
tracklines=0,
cross_track_links=None,
):The multi-line layout does make it hard to fit on a screen - as you say more scrolling. I would even argue this is a good thing, as functions/classes shouldn't have this many arguments (sorry Leighton!). Adopting black will discourage this in new code. In hindsight, given there are lots of (x, y) pairs in GenomeDiagram, perhaps passing these points a 2-tuples would have been neater for the API (but we're stuck with this now for backward compatibility). As an aside, there is probably a flake8 plugin for this kind of complexity check? (Update: pylint has R0902 "Too many instance attributes" and R0913 "Too many arguments", not sure if there is a flake8 ecosystem equivalent) As you say, "it takes away much of the freedom to sort/arrange things in a meaningful manner". I highlighted the example or horizontal placement of some multi-line comments in this pull request - do you have another example in GenomeDiagram? |
No apology necessary :D It's bad design and I should have used something One of the things I like about |
|
When reading PEP8 and looking at all the examples in the Python documentation, there is a clear preference for using line continuation using parentheses (brackets, etc.), together with an indentation to the parentheses level. One example of "taking away the freedom to sort things in a meaningful way": # before black
def draw_box(point1, point2,
color=colors.lightgreen, border=None, colour=None,
**kwargs):Here the author has obviously organized the arguments in a meaningful manner; the two necessary and important arguments on the first line, optional formatting parameters on the second, optional other parameters last. def draw_box(
point1, point2, color=colors.lightgreen, border=None, colour=None, **kwargs
):I don't write much new code, here in Biopython I'm mostly working on existing code. Often, I don't have a clue what a class/method/function is doing exactly after I read the code for the first time, so I need to become acquainted with the code. And this is easier when seeing more of the code at the same time, without too much scrolling up and down. Also, a meaningful and visible sorting of arguments will help. |
|
The Black will squeeze things down to one line if it fits (as here). It will respect comments though, so black is happy with this: def draw_box(
point1,
point2,
# Optional color arguments,
color=colors.lightgreen,
border=None,
colour=None, # historical UK spelling
**kwargs # Accept arbitrary arguments to pass to ReportLab Polygon
):i.e. If there is a real reason for the original grouping (beyond cosmetic line breaking), or other things, you can make it explicit. Granted this is still much longer than the tree line original. Personally I am OK with the black one line version here. The meaning is still there in the Python mandatory vs optional arguments, but accept it is less visually emphasised. |
As that original author, my view is that the I appreciate that there are diverse, strong and heartfelt opinions about code style snd formatting, and preferences for what is most readable. I guess this code sat in the "not brilliantly written, but forced to be readable" category, and after |
|
I found it interesting, that without any knowledge of the |
|
I've applied the minor improvements noticed via the black changes in #2127 (which is why there are now loads of merge conflicts). I don't mind redoing this branch (it should be as simple as re-running black, and cherry-picking the commit to undo the slice changes which would otherwise trigger flake8 E203), but it seems it would not be universally welcome at this time. I'm going to leave this open until at least the BOSC 2019 CoFest meeting next month, when some of the Biopython team will be able to have an in person discussion, and perhaps experiment further with black. |
|
After discussing at CoFest I am in favor of using black. |
|
Closing in favour of #2251 (done as a new pull request to preserve this version and comments as a medium term record of the discussion). |
This pull request is a test case for issue #2008, chosen since the GenomeDiagram author @widdowquinn is a fan of the black tool and it's output, and we historically have had some variation in style between modules.
Note that I reverted two black edits (white space with slicing) due to a known disagreement between black and flake8 over the PEP8 ruling (looks like a flake8 false positive).
I also manually reviewed and fixed some multi-line comments (previously vertically aligned with spaces), in general making them into one-line comments.
I hereby agree to dual licence this and any previous contributions under both
the Biopython License Agreement AND the BSD 3-Clause License.
I have read the
CONTRIBUTING.rstfile, have runflake8locally, andunderstand that AppVeyor and TravisCI will be used to confirm the Biopython unit
tests and style checks pass with these changes.
I have added my name to the alphabetical contributors listings in the files
NEWS.rstandCONTRIB.rstas part of this pull request, am listedalready, or do not wish to be listed. (This acknowledgement is optional.)