PEP8項目まとめ その2(Whitespace in Expressions and Statements)

前回の続き

Whitespace in Expressions and Statements

Pet Peeves

Avoid extraneous whitespace in the following situations:

PEP8 Item pep8 ErrorCode
Immediately inside parentheses, brackets or braces. E201, E202
Immediately before a comma, semicolon, or colon. E203,
Immediately before the open parenthesis that starts the argument list of a function call E211
Immediately before the open parenthesis that starts an indexing or slicing E211(違うかも)
More than one space around an assignment (or other) operator to align it with another. E221, E222
-- E223(tab before operator), E224(tab after operator)
-- E231(missing whitespace after ","), E241(multiple spaces after ",": デフォルトでチェック無効), E242(tab after ",": デフォルトでチェック無効)

Other Recommendations

PEP8 Item pep8 ErrorCode
Always surround these binary operators with a single space on either side: assignment (=), augmented assignment (+=, -= etc.), comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not), Booleans (and, or, not). E225
If operators with different priorities are used, consider adding whitespace around the operators with the lowest priority(ies). Use your own judgement; however, never use more than one space, and always have the same amount of whitespace on both sides of a binary operator. E221, E222, E226(missing whitespace around arithmetic operator: デフォルトでチェック無効), E227, E228
-- E223(tab before operator), E224(tab after operator)
Don't use spaces around the = sign when used to indicate a keyword argument or a default parameter value. E251
-- E271, E272, E273, E274
Compound statements (multiple statements on the same line) are generally discouraged. --
While sometimes it's okay to put an if/for/while with a small body on the same line, never do this for multi-clause statements. Also avoid folding such long lines! --

サンプルコードでpep8モジュールの動作を確認しないとこの対応で正しいのか不明なので、後日検証する。