Skip to content

Format python as python #15403

Closed
Closed

Description

@phlax

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

https://github.com/google?q=&type=&language=python&sort=

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

  1. added
    triage
    on Mar 10, 2021
  2. phlax commented on Mar 10, 2021

    @phlax
    MemberAuthor

    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

  3. snowp commented on Mar 10, 2021

    @snowp
    Contributor

    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.

  4. phlax commented on Mar 10, 2021

    @phlax
    MemberAuthor

    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

  5. htuch commented on Mar 10, 2021

    @htuch
    Member

    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.

  6. phlax commented on Mar 10, 2021

    @phlax
    MemberAuthor

    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.

    tbh that points towards using black

    i 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

  7. htuch commented on Mar 10, 2021

    @htuch
    Member

    @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?

  8. moderation commented on Mar 10, 2021

    @moderation
    Contributor

    I don't do a lot of Python^ but really like black as I like go 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

  9. phlax commented on Mar 11, 2021

    @phlax
    MemberAuthor

    I don't do a lot of Python^ but really like black as I like go fmt. It removes the topic of formatting all together.

    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

    can you point to some example of readability-challenged code the tooling provides?

    not without a long and opinionated take down of black

    (see here for a related discussion i was involved in recently - translate/translate#4131)

    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?

    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

  10. added and removed
    triage
    on Mar 11, 2021
  11. phlax commented on Mar 11, 2021

    @phlax
    MemberAuthor

    /assign phlax

  12. github-actions commented on Apr 10, 2021

    @github-actions

    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.

  13. added
    stale
    on Apr 10, 2021
  14. phlax commented on Apr 10, 2021

    @phlax
    MemberAuthor

    bump

  15. removed
    stale
    on Apr 10, 2021
  16. github-actions commented on May 10, 2021

    @github-actions

    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.

  17. added
    stale
    on May 10, 2021
  18. added
    no stalebot
    and removed
    stale
    on May 10, 2021
  19. phlax commented on Jan 21, 2022

    @phlax
    MemberAuthor

    closing this, as this is mostly resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

no stalebottech debt

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions