@@ -161,13 +161,14 @@ Import each module using the full pathname location of the module.
161161<a id =" s2.3.1-pros " ></a >
162162#### 2.3.1 Pros
163163
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.
165166
166167<a id =" S2.3.2-cons " ></a >
167168#### 2.3.2 Cons
168169
169170Makes it harder to deploy code because you have to replicate the package
170- hierarchy.
171+ hierarchy. Not really a problem with modern deployment mechanisms.
171172
172173<a id =" s2.3.3-decision " ></a >
173174#### 2.3.3 Decision
@@ -176,14 +177,38 @@ All new code should import each module by its full package name.
176177
177178Imports should be as follows:
178179
180+ Yes:
181+
179182``` python
180- # Reference in code with complete name.
183+ # Reference absl.flags in code with the complete name (verbose) .
181184import absl.flags
185+ from doctor.who import jodie
186+
187+ FLAGS = absl.flags.FLAGS
188+ ```
182189
183- # Reference in code with just module name (preferred).
190+ ``` python
191+ # Reference flags in code with just the module name (common).
184192from absl import flags
193+ from doctor.who import jodie
194+
195+ FLAGS = flags.FLAGS
185196```
186197
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+
187212<a id =" s2.4-exceptions " ></a >
188213<a id =" exceptions " ></a >
189214### 2.4 Exceptions
@@ -1049,7 +1074,7 @@ and `enum`).
10491074
10501075< a id = " s2.20-modern-python" >< / a>
10511076< 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
10531078
10541079Python 3 is here! While not every project is ready to
10551080use it yet, all code should be written to be 3 compatible (and tested under
@@ -1385,8 +1410,8 @@ No: golomb4 = [
13851410
13861411Two blank lines between top- level definitions, be they function or class
13871412definitions. 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.
13901415
13911416< a id = " s3.6-whitespace" >< / a>
13921417< a id = " whitespace" >< / a>
@@ -1572,24 +1597,27 @@ Certain aspects of a function should be documented in special sections, listed
15721597below. Each section begins with a heading line, which ends with a colon.
15731598Sections should be indented two spaces, except for the heading.
15741599
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)
15861613: 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.
15911618
1592- [*Raises:*](#doc-function-raises) {#doc-function-raises}
1619+ <a id="doc-function-raises"></a>
1620+ [*Raises:*](#doc-function-raises)
15931621: List all exceptions that are relevant to the interface.
15941622
15951623```python
@@ -2098,7 +2126,7 @@ Always use a `.py` filename extension. Never use dashes.
20982126
20992127< a id =" s3.16.3-file-naming" >< / a>
21002128< a id =" file-naming" >< / a>
2101- # ### 3.16.3 File Naming {#s3.16.3-file-naming}
2129+ # ### 3.16.3 File Naming
21022130
21032131Python filenames must have a `.py` extension and must not contain dashes (`- ` ).
21042132This 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:
24222450# ### 3.19.6 Type Aliases
24232451
24242452You 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
24272454\_Private.
24282455
24292456For example, if the name of module together with the type is too long :
24302457
24312458```python
2432- SomeType = module_with_long_name.TypeWithLongName
2459+ _ShortName = module_with_long_name.TypeWithLongName
2460+ ComplexMap = Mapping[Text, List[Tuple[int , int ]]]
24332461```
24342462
24352463Other examples are complex nested types and multiple return variables from a
0 commit comments