Last active
January 30, 2026 02:45
-
-
Save tonycoco/8c3690aec999c66d8cd07ac0321cbe44 to your computer and use it in GitHub Desktop.
Google Python Style Guide Settings for Ruff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Project settings should be first... | |
| # Reference: https://google.github.io/styleguide/pyguide.html | |
| # These settings follow the `pylintrc` file outlined above as close as possible. | |
| # By omitting `[tool.ruff]` for each section of the options, you can place these settings in a `ruff.toml` file as well. | |
| [tool.ruff] | |
| fix = true | |
| line-length = 80 | |
| preview = true | |
| target-version = "py312" | |
| exclude = ["third_party"] | |
| [tool.ruff.format] | |
| preview = true | |
| docstring-code-format = true | |
| [tool.ruff.lint] | |
| preview = true | |
| dummy-variable-rgx = "^\\*{0,2}(_$|unused_|dummy_)" | |
| logger-objects = ["logging", "absl.logging", "tensorflow.io.logging"] | |
| task-tags = ["TODO"] | |
| # See: https://github.com/astral-sh/ruff/issues/970 | |
| extend-select = [ | |
| "D419", # empty-docstring | |
| "E501", # line-too-long | |
| "W291", # trailing-whitespace | |
| "PLC0414", # useless-import-alias | |
| "PLC2401", # non-ascii-name | |
| "PLC2801", # unnecessary-dunder-call | |
| "PLC3002", # unnecessary-direct-lambda-call | |
| "PLE0101", # return-in-init | |
| "F706", # return-outside-function | |
| "F704", # yield-outside-function | |
| "PLE0115", # nonlocal-and-global | |
| "PLE0117", # nonlocal-without-binding | |
| "PLE0241", # duplicate-bases | |
| "PLE0302", # unexpected-special-method-signature | |
| "PLE0604", # invalid-all-object | |
| "PLE0605", # invalid-all-format | |
| "PLE0643", # potential-index-error | |
| "PLE0704", # misplaced-bare-raise | |
| "PLE1141", # dict-iter-missing-items | |
| "PLE1142", # await-outside-async | |
| "PLE1205", # logging-too-many-args | |
| "PLE1206", # logging-too-few-args | |
| "PLE1307", # bad-string-format-type | |
| "PLE1310", # bad-str-strip-call | |
| "PLE1507", # invalid-envvar-value | |
| "PLE1519", # singledispatch-method | |
| "PLE1520", # singledispatchmethod-function | |
| "PLE2502", # bidirectional-unicode | |
| "PLE2510", # invalid-character-backspace | |
| "PLE2512", # invalid-character-sub | |
| "PLE2513", # invalid-character-esc | |
| "PLE2514", # invalid-character-nul | |
| "PLE2515", # invalid-character-zero-width-space | |
| "PLE4703", # modified-iterating-set | |
| "PLW0108", # unnecessary-lambda | |
| "PLW0127", # self-assigning-variable | |
| "PLW0128", # redeclared-assigned-name | |
| "PLW0129", # assert-on-string-literal | |
| "B033", # duplicate-value | |
| "PLW0131", # named-expr-without-context | |
| "PLE0116", # continue-in-finally | |
| "PLW0177", # nan-comparison | |
| "PLW0211", # bad-staticmethod-argument | |
| "PLW0244", # redefined-slots-in-subclass | |
| "PLW0245", # super-without-brackets | |
| "PLW0602", # global-variable-not-assigned | |
| "PLW0604", # global-at-module-level | |
| "F401", # unused-import | |
| "F841", # unused-variable | |
| "E722", # bare-except | |
| "PLW0711", # binary-op-exception | |
| "PLW1501", # bad-open-mode | |
| "PLW1507", # shallow-copy-environ | |
| "PLW1508", # invalid-envvar-default | |
| "PLW1509", # subprocess-popen-preexec-fn | |
| "PLW1514", # unspecified-encoding | |
| "PLW2101", # useless-with-lock | |
| "PLW3301", # nested-min-max | |
| ] | |
| ignore = [ | |
| "PLR0124", # comparison-with-itself | |
| "PLR0202", # no-classmethod-decorator | |
| "PLR0203", # no-staticmethod-decorator | |
| "UP004", # useless-object-inheritance | |
| "PLR0206", # property-with-parameters | |
| "PLR0904", # too-many-public-methods | |
| "PLR0911", # too-many-return-statements | |
| "PLR0912", # too-many-branches | |
| "PLR0913", # too-many-arguments | |
| "PLR0914", # too-many-locals | |
| "PLR0915", # too-many-statements | |
| "PLR0916", # too-many-boolean-expressions | |
| "PLR0917", # too-many-positional-arguments | |
| "PLR1702", # too-many-nested-blocks | |
| "PLR1704", # redefined-argument-from-local | |
| "PLR1708", # stop-iteration-return | |
| "PLR1711", # useless-return | |
| "C416", # unnecessary-comprehension | |
| "PLR1733", # unnecessary-dict-index-lookup | |
| "PLR1736", # unnecessary-list-index-lookup | |
| "PLW0120", # useless-else-on-loop | |
| "PLW0406", # import-self | |
| "PLW0603", # global-statement | |
| "E701", # multiple-statements-on-one-line (to allow single-line-if-stmt) | |
| ] | |
| [tool.ruff.lint.isort] | |
| # Reference: https://pycqa.github.io/isort/docs/configuration/options.html#profile | |
| # This follows the `isort` profile for `google`. | |
| # Ruff's implementation of isort does not include the following settings... | |
| # profile = "google" | |
| # lexicographical = true | |
| # line-length = 1000 | |
| # group-by-package = true | |
| force-single-line = true | |
| force-sort-within-sections = true | |
| known-third-party = ["enchant", "absl"] | |
| single-line-exclusions = [ | |
| "typing", | |
| ] | |
| order-by-type = false | |
| [tool.ruff.lint.pydocstyle] | |
| convention = "google" | |
| [tool.ruff.lint.pylint] | |
| max-args = 5 | |
| max-branches = 12 | |
| max-returns = 6 | |
| max-statements = 50 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment