@@ -4,8 +4,49 @@ Prefer only GitHub-flavored Markdown in external text.
44See README.md for details.
55-->
66
7+ <!--
8+ Drake authors:
9+ This should be synchronized with the relevant styles in
10+ `include/styleguide.css`.
11+ -->
12+
13+ <style >
14+ .drake {
15+ font-weight : bold ;
16+ color : purple ;
17+ }
18+
19+ .nondrake {
20+ text-decoration : line-through ;
21+ color : DeepPink ;
22+ }
23+ </style >
24+
725# Google Python Style Guide
826
27+ <p class =" drake " >Forked and adapted from the
28+ <a href =" https://google.github.io/styleguide/pyguide.html " >Google style
29+ guide</a >. Many references to Google are deliberately left in to minimize
30+ merge conflicts.</p >
31+
32+ <p >Where Drake-specific rules contradict previous Google conventions, the text
33+ is retained for reference but otherwise marked <span class =" nondrake " >with a
34+ strikethrough</span >. The style is intentionally difficult to read in the
35+ normal course of perusal. Copying-and-pasting, or even simply highlighting the
36+ text, will facilitate reading if necessary.
37+
38+ Rules specific to Drake <span class =" drake " >are highlighted like this</span > for
39+ clarity and easier maintainability.
40+ </p >
41+
42+ <p class =" drake " >
43+ A large number of sections are intentionally hidden, as they do not apply to
44+ Drake development. For all other aspects of code style, please see Drake's
45+ <a href =" https://drake.mit.edu/code_style_guide.html#python-style " >
46+ Code Style Guide</a > documentation page.
47+ </p >
48+
49+ <!--
950
1051<a id="background"></a>
1152## 1 Background
@@ -1535,13 +1576,22 @@ This line is used by the kernel to find the Python interpreter, but is ignored
15351576by Python when importing modules. It is only necessary on a file that will be
15361577executed directly.
15371578
1579+ -->
1580+
15381581<a id =" s3.8-comments " ></a >
15391582<a id =" comments " ></a >
15401583### 3.8 Comments and Docstrings
15411584
15421585Be sure to use the right style for module, function, method docstrings and
15431586inline comments.
15441587
1588+ <span class =" drake " >
1589+ In general, the semantic rules outlined below should be enforced by reviewers.
1590+ However, the formatting (e.g. indentations, lines, etc.) will be enforced by
1591+ automated lint tooling (e.g. ` pycodestyle ` ), and should not be remarked upon by
1592+ reviewers.
1593+ </span >
1594+
15451595<a id =" s3.8.1-comments-in-doc-strings " ></a >
15461596<a id =" comments-in-doc-strings " ></a >
15471597#### 3.8.1 Docstrings
@@ -1552,20 +1602,34 @@ extracted automatically through the `__doc__` member of the object and are used
15521602by ` pydoc ` .
15531603(Try running ` pydoc ` on your module to see how it looks.) Always use the three
15541604double-quote ` """ ` format for docstrings (per [ PEP
1555- 257](https://www.google.com/url?sa=D&q=http://www.python.org/dev/peps/pep-0257/)).
1605+ 257] ( http://www.python.org/dev/peps/pep-0257/ ) ).
1606+ <span class =" nondrake " >
15561607A docstring should be organized as a summary line (one physical line) terminated
15571608by a period, question mark, or exclamation point, followed by a blank line,
15581609followed by the rest of the docstring starting at the same cursor position as
1559- the first quote of the first line. There are more formatting guidelines for
1610+ the first quote of the first line.
1611+ </span >
1612+ <span class =" drake " >
1613+ Docstrings should conform to PEP 257 with one exception: summary lines are not
1614+ required (but are acceptable).
1615+ </span >
1616+ There are more formatting guidelines for
15601617docstrings below.
15611618
15621619<a id =" s3.8.2-comments-in-modules " ></a >
15631620<a id =" comments-in-modules " ></a >
15641621#### 3.8.2 Modules
15651622
1623+ <span class =" nondrake " >
15661624Every file should contain license boilerplate. Choose the appropriate
15671625boilerplate for the license used by the project (for example, Apache 2.0, BSD,
15681626LGPL, GPL)
1627+ </span >
1628+
1629+ <span class =" drake " >
1630+ At present, Drake's code (C++, Python, Skylark, etc.) does not explicitly
1631+ declare its license.
1632+ </span >
15691633
15701634<a id =" s3.8.3-functions-and-methods " ></a >
15711635<a id =" functions-and-methods " ></a >
@@ -1575,7 +1639,7 @@ In this section, "function" means a method, function, or generator.
15751639
15761640A function must have a docstring, unless it meets all of the following criteria:
15771641
1578- - not externally visible
1642+ - < span class = " nondrake " > not externally visible</ span >
15791643- very short
15801644- obvious
15811645
@@ -1603,12 +1667,19 @@ Sections should be indented two spaces, except for the heading.
16031667[ * Args:* ] ( #doc-function-args )
16041668: List each parameter by name. A description should follow the name, and be
16051669separated by a colon and a space. If the description is too long to fit on a
1606- single 80-character line, use a hanging indent of 2 or 4 spaces (be
1670+ single <span class =" nondrake " >80-character</span >
1671+ <span class =" drake " >79-character\* </span > line, use a
1672+ hanging indent of 2 or 4 spaces (be
16071673consistent with the rest of the file).<br >
16081674The description should include required type(s) if the code does not contain
16091675a corresponding type annotation.<br >
16101676If a function accepts ` *foo ` (variable length argument lists) and/or ` **bar `
16111677(arbitrary keyword arguments), they should be listed as ` *foo ` and ` **bar ` .
1678+ <br >
1679+
1680+ <span class =" drake " >Obvious parameters do not need to be documented.</span >
1681+
1682+ <span class =" drake " >\* See [ PEP 8 - Maximum Line Length] ( https://www.python.org/dev/peps/pep-0008/#maximum-line-length ) </span >
16121683
16131684<a id =" doc-function-returns " ></a >
16141685[ * Returns:* (or * Yields:* for generators)] ( #doc-function-returns )
@@ -1659,10 +1730,15 @@ def fetch_bigtable_rows(big_table, keys, other_silly_variable=None):
16591730#### 3.8.4 Classes
16601731
16611732Classes should have a docstring below the class definition describing the class.
1662- If your class has public attributes, they should be documented here in an
1733+ If your class has public attributes, they
1734+ <span class =" nondrake " >should</span >
1735+ <span class =" drake " >may</span >
1736+ be documented here in an
16631737` Attributes ` section and follow the same formatting as a
16641738[ function's ` Args ` ] ( #doc-function-args ) section.
16651739
1740+ <span class =" drake " >Attributes are not always documented for classes.</span >
1741+
16661742``` python
16671743class SampleClass (object ):
16681744 """ Summary of class here.
@@ -1684,6 +1760,8 @@ class SampleClass(object):
16841760 """ Performs operation blah."""
16851761```
16861762
1763+ <!--
1764+
16871765<a id="comments-in-block-and-inline"></a>
16881766<a id="s3.8.5-comments-in-block-and-inline"></a>
16891767#### 3.8.5 Block and Inline Comments
@@ -1714,7 +1792,10 @@ knows Python (though not what you're trying to do) better than you do.
17141792# the next element is i+1
17151793```
17161794
1795+ -->
1796+
17171797<!-- The next section is copied from the C++ style guide. -->
1798+
17181799<a id =" s3.8.6-punctuation-spelling-and-grammar " ></a >
17191800<a id =" punctuation-spelling-and-grammar " ></a >
17201801#### 3.8.6 Punctuation, Spelling and Grammar
@@ -1732,6 +1813,7 @@ using a comma when you should be using a semicolon, it is very important that
17321813source code maintain a high level of clarity and readability. Proper
17331814punctuation, spelling, and grammar help with that goal.
17341815
1816+ <!--
17351817<a id="s3.9-classes"></a>
17361818<a id="classes"></a>
17371819### 3.9 Classes
@@ -2735,4 +2817,4 @@ style is also important. If code you add to a file looks drastically different
27352817from the existing code around it, it throws readers out of their rhythm when
27362818they go to read it. Avoid this.
27372819
2738-
2820+ -->
0 commit comments