LoginSignup
9
10

More than 3 years have passed since last update.

Python スタイルガイドとリンター

Last updated at Posted at 2019-08-09

はじめに

Pythonのスタイルガイドとリンターのまとめ。

Style Guide

Google Python Style Guide

Googleオフィシャルのスタイルガイド。

Google Python Style Guide

Style Guide for Python Code

PEP8として知られるPython.orgオフィシャルのスタイルガイド。

付随してPythonのAPIドキュメンテーションのガイドもある。

PEP 257 -- Docstring Conventions

Linter

PythonはJavaと違って、Linterの機能がケースバイケースで種類がはっきりと分類できない。Linterの機能を style check機能, bug check機能, format機能に大別して、主要なLinterの機能を表形式でまとめたものが下表である。

tool name style check bug check format
pep8 x
pylint x x
pyflakes x
flake8 (≒pyflakes+pep8) x x
autopep8 x x
black x
yapf (mainteined by Google) x

参考サイト

名称に8とつくtoolはPEP8に準拠したstyle checkを行うものである。

ドキュメンテーションスタイル

Pythonではソースコード上にdocstringと呼ばれる、APIを説明する特別なコメントを書く。これは、JavaのJavaDocやC++のDoxgenと同じようなものだが、規約がゆるく何でもアリな仕様。Pythonのdocstring(ドキュメンテーション文字列)の書き方 によると3つの異なるスタイルが普及している。

  1. sphinx
  2. numpy
  3. google

おおむね、上から順にタイピング量が多い印象。 googleスタイルがおすすめ。

9
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
10