Skip to main content

Linting & Formatting


ruff

python3 -m pip install ruff
pyproject.toml
[tool.ruff]
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]

line-length = 100
indent-width = 4

[tool.ruff.lint]
select = ["E4", "E7", "E9", "F", "I"]
ignore = []

fixable = ["ALL"]
unfixable = []

dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
ruff format **/*.py

mypy

python3 -m pip install mypy
pyproject.toml
[tool.mypy]

[[tool.mypy.overrides]]
# module = "<pattern>" # ex) "module.*"
# 옵션

inline 오류 무시

부분적으로만 무시하고 싶은 경우에는 에러가 발생하는 줄에 # type: ignore[<errorCode>, ...] 주석을 추가하면 됩니다.

a: int = 1.0  # type: ignore[assignment]

pylint, black, isort

pylint

python3 -m pip install pylint
pylint --generate-toml-config >> pyproject.toml
pyproject.toml
[tool.pylint.main]

ignore-patterns = ["^\\.#", ".*_pb2.pyi?"]

[tool.pylint."messages control"]

disable = [
"bad-inline-option",
"bare-except",
"broad-exception-caught",
"deprecated-pragma",
"file-ignored",
"invalid-name",
"line-too-long",
"locally-disabled",
"missing-class-docstring",
"missing-function-docstring",
"missing-module-docstring",
"raw-checker-failed",
"suppressed-message",
"too-few-public-methods",
"too-many-arguments",
"too-many-return-statements",
"useless-suppression",
"use-implicit-booleaness-not-comparison-to-string",
"use-implicit-booleaness-not-comparison-to-zero",
"use-symbolic-message-instead",
]
pylint **/*.py

inline 오류 무시

부분적으로만 무시하고 싶은 경우에는 에러가 발생하는 줄에 # pylint: disable=<errorCode> 주석을 추가하면 됩니다.

a._b = 1  # pylint: disable=protected-access

black

python3 -m pip install black
black **/*.py
pyproject.toml
[tool.black]
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.nox
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
'''
include = '\.pyi?$'
line-length = 100

isort

python3 -m pip install isort
isort --profile black **/*.py
pyproject.toml
[tool.isort]
line_length = 100
profile = "black"
skip_gitignore = true
multi_line_output = 3