Repository navigation
Description
foreword/warning
i have put off raising this issue mostly because to paraphrase einstein:
Im not sure what world war IV will be fought with, but im pretty confident that world war V will be fought with opinions about code formatting
but as i need to work with these files and the problem is imho pretty bad now, i dont want to make it worse and want to be able to use the standard tooling
(i also dont want to start world war V! )
description
as a long term python programmer i find the envoy python very hard to work with - its as if programming in another language.
essentially this is due to the formatting which doesnt match any ive seen before
because the formatting is not a standard, the standard tools dont work - or at very least in order to use them you have to disable many rules that you really dont want to disable
this makes coding in python with this codebase much like climbing without ropes.
running the linter against the codebase exposes a ton of problems
checking the policy - its a "follow google" policy. I would object to this as i believe python should follow python standards, not google/uber/etc standards.
also when i check google's public python repos im seeing mostly sane pythonic formatting (4 space indents - yay!) - im not seeing anything that remotely looks like our python formatting
suggestions
proper pythonic casing
this is so counterintuitive, reading the code its not at all clear what is an object (ie instantiated class), what is a function, what is a method etc
flake8 linting
with only 2 exceptions (W503/W504) i would recommend using pep8 + pyflakes for linting
i dont like black (autoformatting) but i do think its important to have a clear standard that we all work to.
4 space indents
this is something that python devs rarely disagree on.
4-space indents is important in python because whitespace can be both structural and non-structural (ie hanging indents).
Using 2-spaces just breaks the linter - afaict there is no way to change the indent (not sure why you would want to) so you have to disable a ton of rules
Activity
phlax commentedon Mar 10, 2021
as a follow up suggestion it would be great to get some (py)tests in place - this would provide the harness to make climbing much safer indeed
snowp commentedon Mar 10, 2021
I think we should definitely have a consistent style that works with the available tooling. Does the pylintrc provided at https://google.github.io/styleguide/pyguide.html not provide us with proper support for linting Google style?
@lizan @htuch @jmarantz for thoughts on whether it makes sense to stick to Google style or if we should adopt a more common set of guidelines.
phlax commentedon Mar 10, 2021
clicking on the above link - i see 4 space indents and snake casing etc - so im hoping that a lot of what im suggesting is not controversial - at least not in terms of google-style
htuch commentedon Mar 10, 2021
Yeah, as long as we are consistent with some combination of best practices in Python community and any additional guidance that the Google Python style guide brings to the table, I'm good with that.
An example I think of where we see a different between internal vs. external Python style guides is on 2 vs. 4 space indents; since the external one now expresses 4 space is the ideal, let's go with that. I think our own internal conventions have also shifted over time and legacy style for things like casing has become more aligned with the external world.
BTW, I think it's a bad use of maintainer time to worry about formatting during PR review, we should just pick something that is machine enforceable and stick with that. That's the real win of any major effort here IMHO, freeing up time for developers to focus on the semantics rather than syntax.
phlax commentedon Mar 10, 2021
tbh that points towards using
blacki just dont like the code that it produces, and readability counts
imho some of the rules which are afaict non-configurable are not the most readable forms, but it does remove the need for the reviewer to even think about formats
htuch commentedon Mar 10, 2021
@phlax can you point to some example of readability-challenged code the tooling provides? It would help to see. I don't see this being a hard constraint, but something we'd ideally do. Since we use clang-format for C++ code, we have zero discussions over indenting etc. Sometime people mess up things like casing, and clang-tidy has helped us out there but it's not fully formattable.
Is there a middle ground where we don't have auto-format but can at least lint to ensure everything fits the style guidelines and make sure that blocks CI?
moderation commentedon Mar 10, 2021
I don't do a lot of Python^ but really like
blackas I likego fmt. It removes the topic of formatting all together. And I agree with @htuch that machine enforceable is key.^ I maintain a Garmin Connect activity exporter that has quite a few users
phlax commentedon Mar 11, 2021
I think if you write a lot of code then you are more emotionally iinvested in how it should look and what makes it easiest to read
it does remove the conversation tho so perhaps we should move towards it
not without a long and opinionated take down of black
(see here for a related discussion i was involved in recently - translate/translate#4131)
yep we can just use flake8 more strictly
lets tidy up the code and then look at how we keep it auto-tidy - ill add linting as i go tho so we hopefully will be most of the way already
phlax commentedon Mar 11, 2021
/assign phlax
python: Use pythonic casing for variable names (#15479)
github-actions commentedon Apr 10, 2021
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.
phlax commentedon Apr 10, 2021
bump
github-actions commentedon May 10, 2021
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.
phlax commentedon Jan 21, 2022
closing this, as this is mostly resolved