@@ -161,13 +161,14 @@ Import each module using the full pathname location of the module.
161
161
<a id =" s2.3.1-pros " ></a >
162
162
#### 2.3.1 Pros
163
163
164
- Avoids conflicts in module names. Makes it easier to find modules.
164
+ Avoids conflicts in module names or incorrect imports due to the module search
165
+ path not being what the author expected. Makes it easier to find modules.
165
166
166
167
<a id =" S2.3.2-cons " ></a >
167
168
#### 2.3.2 Cons
168
169
169
170
Makes it harder to deploy code because you have to replicate the package
170
- hierarchy.
171
+ hierarchy. Not really a problem with modern deployment mechanisms.
171
172
172
173
<a id =" s2.3.3-decision " ></a >
173
174
#### 2.3.3 Decision
@@ -176,14 +177,38 @@ All new code should import each module by its full package name.
176
177
177
178
Imports should be as follows:
178
179
180
+ Yes:
181
+
179
182
``` python
180
- # Reference in code with complete name.
183
+ # Reference absl.flags in code with the complete name (verbose) .
181
184
import absl.flags
185
+ from doctor.who import jodie
186
+
187
+ FLAGS = absl.flags.FLAGS
188
+ ```
182
189
183
- # Reference in code with just module name (preferred).
190
+ ``` python
191
+ # Reference flags in code with just the module name (common).
184
192
from absl import flags
193
+ from doctor.who import jodie
194
+
195
+ FLAGS = flags.FLAGS
185
196
```
186
197
198
+ No: _ (assume this file lives in ` doctor/who/ ` where ` jodie.py ` also exists)_
199
+
200
+ ``` python
201
+ # Unclear what module the author wanted and what will be imported. The actual
202
+ # import behavior depends on external factors controlling sys.path.
203
+ # Which possible jodie module did the author intend to import?
204
+ import jodie
205
+ ```
206
+
207
+ The directory the main binary is located in should not be assumed to be in
208
+ ` sys.path ` despite that happening in some environments. This being the case,
209
+ code should assume that ` import jodie ` refers to a third party or top level
210
+ package named ` jodie ` , not a local ` jodie.py ` .
211
+
187
212
<a id =" s2.4-exceptions " ></a >
188
213
<a id =" exceptions " ></a >
189
214
### 2.4 Exceptions
@@ -1049,7 +1074,7 @@ and `enum`).
1049
1074
1050
1075
< a id = " s2.20-modern-python" >< / a>
1051
1076
< a id = " modern-python" >< / a>
1052
- # ## 2.20 Modern Python: Python 3 and from \_\_future\_\_ imports {#modern-python}
1077
+ # ## 2.20 Modern Python: Python 3 and from \_\_future\_\_ imports
1053
1078
1054
1079
Python 3 is here! While not every project is ready to
1055
1080
use it yet, all code should be written to be 3 compatible (and tested under
@@ -1385,8 +1410,8 @@ No: golomb4 = [
1385
1410
1386
1411
Two blank lines between top- level definitions, be they function or class
1387
1412
definitions. One blank line between method definitions and between the `class `
1388
- line and the first method. Use single blank lines as you judge appropriate
1389
- within functions or methods.
1413
+ line and the first method. No blank line following a ` def ` line. Use single
1414
+ blank lines as you judge appropriate within functions or methods.
1390
1415
1391
1416
< a id = " s3.6-whitespace" >< / a>
1392
1417
< a id = " whitespace" >< / a>
@@ -1572,24 +1597,27 @@ Certain aspects of a function should be documented in special sections, listed
1572
1597
below. Each section begins with a heading line, which ends with a colon.
1573
1598
Sections should be indented two spaces, except for the heading.
1574
1599
1575
- [*Args:*](#doc-function-args) {#doc-function-args}
1576
- : List each parameter by name. A description should follow the name, and be
1577
- : separated by a colon and a space. If the description is too long to fit on a
1578
- : single 80-character line, use a hanging indent of 2 or 4 spaces (be
1579
- : consistent with the rest of the file).<br/>
1580
- : The description should include required type(s) if the code does not contain
1581
- : a corresponding type annotation.<br/>
1582
- : If a function accepts `*foo` (variable length argument lists) and/or `**bar`
1583
- : (arbitrary keyword arguments), they should be listed as `*foo` and `**bar`.
1584
-
1585
- [*Returns:* (or *Yields:* for generators)](#doc-function-returns) {#doc-function-returns}
1600
+ <a id="doc-function-args"></a>
1601
+ [*Args:*](#doc-function-args)
1602
+ : List each parameter by name. A description should follow the name, and be
1603
+ separated by a colon and a space. If the description is too long to fit on a
1604
+ single 80-character line, use a hanging indent of 2 or 4 spaces (be
1605
+ consistent with the rest of the file).<br>
1606
+ The description should include required type(s) if the code does not contain
1607
+ a corresponding type annotation.<br>
1608
+ If a function accepts `*foo` (variable length argument lists) and/or `**bar`
1609
+ (arbitrary keyword arguments), they should be listed as `*foo` and `**bar`.
1610
+
1611
+ <a id="doc-function-returns"></a>
1612
+ [*Returns:* (or *Yields:* for generators)](#doc-function-returns)
1586
1613
: Describe the type and semantics of the return value. If the function only
1587
- : returns None, this section is not required. It may also be omitted if the
1588
- : docstring starts with Returns ( or Yields) (e.g.
1589
- : `""" Returns row from Bigtable as a tuple of strings.""" `) and the opening
1590
- : sentence is sufficient to describe return value.
1614
+ returns None, this section is not required. It may also be omitted if the
1615
+ docstring starts with Returns or Yields (e.g.
1616
+ `""" Returns row from Bigtable as a tuple of strings.""" `) and the opening
1617
+ sentence is sufficient to describe return value.
1591
1618
1592
- [*Raises:*](#doc-function-raises) {#doc-function-raises}
1619
+ <a id="doc-function-raises"></a>
1620
+ [*Raises:*](#doc-function-raises)
1593
1621
: List all exceptions that are relevant to the interface.
1594
1622
1595
1623
```python
@@ -2098,7 +2126,7 @@ Always use a `.py` filename extension. Never use dashes.
2098
2126
2099
2127
< a id =" s3.16.3-file-naming" >< / a>
2100
2128
< a id =" file-naming" >< / a>
2101
- # ### 3.16.3 File Naming {#s3.16.3-file-naming}
2129
+ # ### 3.16.3 File Naming
2102
2130
2103
2131
Python filenames must have a `.py` extension and must not contain dashes (`- ` ).
2104
2132
This allows them to be imported and unittested. If you want an executable to be
@@ -2422,14 +2450,14 @@ def implicit_optional(a: Text = None) -> Text:
2422
2450
# ### 3.19.6 Type Aliases
2423
2451
2424
2452
You can declare aliases of complex types. The name of an alias should be
2425
- CapWorded; try to describe the composed type and end with " Type" (or " Types" for
2426
- returned tuples). If the alias is used only in this module, it should be
2453
+ CapWorded. If the alias is used only in this module, it should be
2427
2454
\_Private.
2428
2455
2429
2456
For example, if the name of module together with the type is too long :
2430
2457
2431
2458
```python
2432
- SomeType = module_with_long_name.TypeWithLongName
2459
+ _ShortName = module_with_long_name.TypeWithLongName
2460
+ ComplexMap = Mapping[Text, List[Tuple[int , int ]]]
2433
2461
```
2434
2462
2435
2463
Other examples are complex nested types and multiple return variables from a
0 commit comments