-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pre commit #359
base: main
Are you sure you want to change the base?
Pre commit #359
Conversation
thanks SM for taking this up. it is a lot of changes. I may be in the minority opinion here, but I am not very fond of this kind of style
that is prevalent in the black reformatting. I actually find it incredibly more hard to read, debug, and edit than
but maybe that's just something I need to learn to get over. regardless, my vote would be to either remove black or turn off this kind of style, but of course, if I'm in the minority of heavy-user hera_pspec devs, I'm fine w/ it being added. lmk if anyone has thoughts |
FWIW, I also find that kind of choice by Black to be totally baffling. |
@nkern I agree that that is awful formatting. There is an easy way to turn that particular thing off, and I actually tried to find instances of it in this code, but obviously missed a few. Briefly, black will format any list with a trailing comma after the last element on separate lines. Otherwise, if it doesn't have a trailing comma it will try to fit it on one line, and only break if necessary. These apparently had pre-existing trailing commas which signaled black to format it this way. I can fix these particular instances. Usually, as one writes code and black formats the little bits you write, you notice these things and can fix them easily as you go (as you get used to it, you just know ahead of time not to put the comma there for a short list/tuple etc). |
OK @nkern I fixed up some of the most obvious examples of that kind of thing. |
@steven-murray got it, thanks for the explanation! not to nit pick here, but here is another example of a formatting issue that I (personally) think reduces clarity
after
maybe this is another example of an edgecase, but these are kind of scattered all over the place. it also could just be that I don't like putting brackets on their own line, which is very common for black it seems. I guess the question for us to ask (which maybe we did and I missed it since I haven't showed up at pspec telecons lately, sorry), is do most ppl who actively work on hera_pspec (myself, phil, adrian, aew, jianrong, saurabh, adelie, hugh, and others) find that its non-black-conforming code style is a hindrance? let me know if so. or maybe this is a hera-wide software effort? I think I may just have a personal distaste for black in general, but again, if most hera_pspec devs are on board I'm cool with it. and regardless, thanks steven for all of the effort you've put into getting this where it is! maybe others can weigh in on their thoughts if they have them. |
@nkern Thanks for thinking this through thoroughly. With the example you list here, which changes something like this: long_lhs_expression = \
(also_really_long_rhs_expression_that_is
* multiplied_by_another) to this: long_lhs_expression = (
also_really_long_rhs_expression_that_is
* multiplied_by_another
) The explicit rationale is 1. always remove all backslashes because they're brittle (see here for reasons), 2. don't go over 88 characters per line (because that is harder to read and present and look at on github etc.) and 3. putting the final bracket on its own line makes it much easier to see the end of the clause. Number (3) is especially obvious in things like this: def function_with_many_params(
first_param,
second_param = "my default value",
third_param: tuple = ('xx', 'yy'),
):
# code starts!
first_param * second_param
... Note that if the last parenthesis of the function call was right at the end of the I advocate for using black based on essentially three arguments:
</persuasive essay> Having said all that, I realize it's up to the people who actually develop pspec to decide whether they want to do this or not. Either way, if you'd prefer to turn black off, I'd still recommend keeping the pre-commit file with at least the flake8 checks, because I fixed some things that were almost certainly errors by doing that. |
awesome, thanks for your insight steven. I think I would generally agree with all of those things in theory. I think the thing that just gets me in practice, is that I think I just personally disagree with what black sees as "more readable". For example, in your example (as with many examples I see on black docs) of something like this
relative to this
it seems like the above is just taken for granted as "more readable" but, for whatever reason, I just don't see it that way. However, I think this is just the way I "grew-up" reading and writing python code--I probably could get used to the black style, and in this case I certainly don't think its "unreadable" per se, just harder for me. And I do agree with consistency as being a key thing here, so, I think I'm probably fine with turning a minimal flake8+black pre-commit here if everyone else is on board. but perhaps we can just get a weigh-in from some other hera_pspec devs if they have any opinions. |
@steven-murray while we wait on weigh-in from others, an unrelated question: in some areas there is the addition of a # noqa comment, which apparently is a signal to the codecoverage to not check that line. In the case of a function, does it apply to the whole function? and also did you add that or is that something that black added (and if so, why?). thanks! Here is an example in pspecdata.py
|
Hey @nkern , sorry for the delay, was on vacation. So the |
Sorry for the long delay, I studiously ignore my GitHub notifications :/
|
This adds pre-commit and many style checks, in particular flake8 and black.
Looking through all the changes will be a bit laborious... you might want to have a skim through to make sure the overall feel is what you want. If there's any changes that seem like style you don't want, I can change it back.
I have left a few style checks off for now (there were just too many errors and I didn't want to deal with them all at once). They can be turned on one at a time in other PRs.
I also found a few things that seemed like actual errors (small things like missing assertions).