Skip to content
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

Style guidelines. #54

Open
eyeonus opened this issue Feb 14, 2019 · 7 comments
Open

Style guidelines. #54

eyeonus opened this issue Feb 14, 2019 · 7 comments
Labels
guideline Indicates the audience for the "issue" is contributors and colloborators on the project.

Comments

@eyeonus
Copy link
Owner

eyeonus commented Feb 14, 2019

Indentation

  • Use 4 spaces per indentation level.

Suggested Maximum Line Length

  • Limit all lines to a maximum of 79 characters. Feel free to ignore if inconvenient.

Blank Lines

  • Blank lines must have the same indentation level as the immediately following non-blank line. This is an exception to the "No trailing whitespace" rule.

Whitespace in Expressions and Statements

Avoid extraneous whitespace in the following situations:

  • Immediately inside parentheses, brackets or braces.
    Yes: spam(ham[1], {eggs: 2})
    No:  spam( ham[ 1 ], { eggs: 2 } )
  • Between a trailing comma and a following close parenthesis.
    Yes: foo = (0,)
    No:  bar = (0, )
  • Immediately before a comma, semicolon, or colon:
    Yes: if x == 4: print x, y; x, y = y, x
    No:  if x == 4 : print x , y ; x , y = y , x
  • Immediately before the open parenthesis that starts the argument list of a function call:
    Yes: spam(1)
    No:  spam (1)
  • Immediately before the open parenthesis that starts an indexing or slicing:
    Yes: dct['key'] = lst[index]
    No:  dct ['key'] = lst [index]
  • More than one space around an assignment (or other) operator to align it with another.

    Yes:

    x = 1
    y = 2
    long_variable = 3
No:
    x             = 1
    y             = 2
    long_variable = 3

For everything else you might think of, refer to PEP8 as completely optional style advice except where it contradicts the above.

@eyeonus eyeonus added the guideline Indicates the audience for the "issue" is contributors and colloborators on the project. label Feb 14, 2019
@kmpm
Copy link
Collaborator

kmpm commented Feb 16, 2019

Do you know any other python project that have the "Blank lines must have the same indentation level as the immediately following non-blank line" rule? Or for that matter the rest of the guide.

I'm just trying to automate my toolset and would appreciate hints on how other have configured their linters etc.

@eyeonus
Copy link
Owner Author

eyeonus commented Feb 16, 2019

I don't know of any other python projects, period.

@eyeonus
Copy link
Owner Author

eyeonus commented Feb 26, 2019

Regarding the indentation, I'm still trying to figure out how pylint checkers work in order to make one to correctly handle the indenting, as well as setting up pylint to conform to the style being used in TD, such as naming conventions, etc.

I'm not finding very good documentation on how checkers work, and the custom_raw.py example isn't much help, but I did manage to figure out how to correctly automate the indentation using find and sed:

find * -type f -name "*.py" -print0 | xargs -0 sed -i -e '/^ *$/{N;s/^ *\n\( *\)\(.*\)/\1\n\1\2/}'

@aadler
Copy link
Contributor

aadler commented Feb 17, 2020

As this is written in Python 3.x, using PEP 8 as the style guide makes the most sense, no?

@eyeonus
Copy link
Owner Author

eyeonus commented Feb 17, 2020

Except as the above differs from that, sure.

@kmpm
Copy link
Collaborator

kmpm commented Feb 4, 2022

How can { eggs: 2 } be OK if spaces immediately inside brackets or braces is to be avoided?
Is it a typo or can you clarify

@eyeonus
Copy link
Owner Author

eyeonus commented Feb 4, 2022

Typo, I think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guideline Indicates the audience for the "issue" is contributors and colloborators on the project.
Projects
None yet
Development

No branches or pull requests

3 participants