@@ -4,8 +4,49 @@ Prefer only GitHub-flavored Markdown in external text.
4
4
See README.md for details.
5
5
-->
6
6
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
+
7
25
# Google Python Style Guide
8
26
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
+ <!--
9
50
10
51
<a id="background"></a>
11
52
## 1 Background
@@ -1535,13 +1576,22 @@ This line is used by the kernel to find the Python interpreter, but is ignored
1535
1576
by Python when importing modules. It is only necessary on a file that will be
1536
1577
executed directly.
1537
1578
1579
+ -->
1580
+
1538
1581
<a id =" s3.8-comments " ></a >
1539
1582
<a id =" comments " ></a >
1540
1583
### 3.8 Comments and Docstrings
1541
1584
1542
1585
Be sure to use the right style for module, function, method docstrings and
1543
1586
inline comments.
1544
1587
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
+
1545
1595
<a id =" s3.8.1-comments-in-doc-strings " ></a >
1546
1596
<a id =" comments-in-doc-strings " ></a >
1547
1597
#### 3.8.1 Docstrings
@@ -1552,20 +1602,34 @@ extracted automatically through the `__doc__` member of the object and are used
1552
1602
by ` pydoc ` .
1553
1603
(Try running ` pydoc ` on your module to see how it looks.) Always use the three
1554
1604
double-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 " >
1556
1607
A docstring should be organized as a summary line (one physical line) terminated
1557
1608
by a period, question mark, or exclamation point, followed by a blank line,
1558
1609
followed 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
1560
1617
docstrings below.
1561
1618
1562
1619
<a id =" s3.8.2-comments-in-modules " ></a >
1563
1620
<a id =" comments-in-modules " ></a >
1564
1621
#### 3.8.2 Modules
1565
1622
1623
+ <span class =" nondrake " >
1566
1624
Every file should contain license boilerplate. Choose the appropriate
1567
1625
boilerplate for the license used by the project (for example, Apache 2.0, BSD,
1568
1626
LGPL, 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 >
1569
1633
1570
1634
<a id =" s3.8.3-functions-and-methods " ></a >
1571
1635
<a id =" functions-and-methods " ></a >
@@ -1575,7 +1639,7 @@ In this section, "function" means a method, function, or generator.
1575
1639
1576
1640
A function must have a docstring, unless it meets all of the following criteria:
1577
1641
1578
- - not externally visible
1642
+ - < span class = " nondrake " > not externally visible</ span >
1579
1643
- very short
1580
1644
- obvious
1581
1645
@@ -1603,12 +1667,19 @@ Sections should be indented two spaces, except for the heading.
1603
1667
[ * Args:* ] ( #doc-function-args )
1604
1668
: List each parameter by name. A description should follow the name, and be
1605
1669
separated 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
1607
1673
consistent with the rest of the file).<br >
1608
1674
The description should include required type(s) if the code does not contain
1609
1675
a corresponding type annotation.<br >
1610
1676
If a function accepts ` *foo ` (variable length argument lists) and/or ` **bar `
1611
1677
(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 >
1612
1683
1613
1684
<a id =" doc-function-returns " ></a >
1614
1685
[ * Returns:* (or * Yields:* for generators)] ( #doc-function-returns )
@@ -1659,10 +1730,15 @@ def fetch_bigtable_rows(big_table, keys, other_silly_variable=None):
1659
1730
#### 3.8.4 Classes
1660
1731
1661
1732
Classes 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
1663
1737
` Attributes ` section and follow the same formatting as a
1664
1738
[ function's ` Args ` ] ( #doc-function-args ) section.
1665
1739
1740
+ <span class =" drake " >Attributes are not always documented for classes.</span >
1741
+
1666
1742
``` python
1667
1743
class SampleClass (object ):
1668
1744
""" Summary of class here.
@@ -1684,6 +1760,8 @@ class SampleClass(object):
1684
1760
""" Performs operation blah."""
1685
1761
```
1686
1762
1763
+ <!--
1764
+
1687
1765
<a id="comments-in-block-and-inline"></a>
1688
1766
<a id="s3.8.5-comments-in-block-and-inline"></a>
1689
1767
#### 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.
1714
1792
# the next element is i+1
1715
1793
```
1716
1794
1795
+ -->
1796
+
1717
1797
<!-- The next section is copied from the C++ style guide. -->
1798
+
1718
1799
<a id =" s3.8.6-punctuation-spelling-and-grammar " ></a >
1719
1800
<a id =" punctuation-spelling-and-grammar " ></a >
1720
1801
#### 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
1732
1813
source code maintain a high level of clarity and readability. Proper
1733
1814
punctuation, spelling, and grammar help with that goal.
1734
1815
1816
+ <!--
1735
1817
<a id="s3.9-classes"></a>
1736
1818
<a id="classes"></a>
1737
1819
### 3.9 Classes
@@ -2735,4 +2817,4 @@ style is also important. If code you add to a file looks drastically different
2735
2817
from the existing code around it, it throws readers out of their rhythm when
2736
2818
they go to read it. Avoid this.
2737
2819
2738
-
2820
+ -->
0 commit comments