Skip to content

Commit 7751268

Browse files
Google Python teamgpshead
Google Python team
authored andcommitted
Project import generated by Copybara.
PiperOrigin-RevId: 543420495
1 parent 2173b8d commit 7751268

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

pyguide.md

+25-28
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,10 @@ Module names can still collide. Some module names are inconveniently long.
257257
- `y` conflicts with a common parameter name that is part of the public
258258
API (e.g., `features`).
259259
- `y` is an inconveniently long name.
260-
* Use `import y as z` only when `z` is a standard abbreviation (e.g., `np` for
261-
`numpy`).
260+
- `y` is too generic in the context of your code (e.g., `from
261+
storage.file_system import options as fs_options`).
262+
* Use `import y as z` only when `z` is a standard abbreviation (e.g., `import
263+
numpy as np`).
262264

263265
For example the module `sound.effects.echo` may be imported as follows:
264266

@@ -1794,8 +1796,9 @@ No: # Stuff on first line forbidden.
17941796
17951797
Trailing commas in sequences of items are recommended only when the closing
17961798
container token `]`, `)`, or `}` does not appear on the same line as the final
1797-
element. The presence of a trailing comma is also used as a hint to our Python
1798-
code auto-formatter
1799+
element, as well as for tuples with a single element. The presence of a trailing
1800+
comma is also used as a hint to our Python code auto-formatter
1801+
17991802
<a id="Python_Interpreter"></a>
18001803
<a id="s3.7-shebang-line"></a>
18011804
<a id="37-shebang-line"></a>
@@ -1955,11 +1958,12 @@ aptly described using a one-line docstring.
19551958
19561959
<a id="doc-function-returns"></a>
19571960
[*Returns:* (or *Yields:* for generators)](#doc-function-returns)
1958-
: Describe the type and semantics of the return value. If the function only
1959-
returns None, this section is not required. It may also be omitted if the
1960-
docstring starts with Returns or Yields (e.g. `"""Returns row from Bigtable
1961-
as a tuple of strings."""`) and the opening sentence is sufficient to
1962-
describe the return value. Do not imitate 'NumPy style'
1961+
: Describe the semantics of the return value, including any type information
1962+
that the type annotation does not provide. If the function only returns
1963+
None, this section is not required. It may also be omitted if the docstring
1964+
starts with Returns or Yields (e.g. `"""Returns row from Bigtable as a tuple
1965+
of strings."""`) and the opening sentence is sufficient to describe the
1966+
return value. Do not imitate 'NumPy style'
19631967
([example](http://numpy.org/doc/stable/reference/generated/numpy.linalg.qr.html)),
19641968
which frequently documents a tuple return value as if it were multiple
19651969
return values with individual names (never mentioning the tuple). Instead,
@@ -3246,8 +3250,8 @@ def next(l: list[_T]) -> _T:
32463250
return l.pop()
32473251
32483252
def print_when_called(f: Callable[_P, _T]) -> Callable[_P, _T]:
3249-
def inner(*args: P.args, **kwargs: P.kwargs) -> R:
3250-
print('Function was called')
3253+
def inner(*args: _P.args, **kwargs: _P.kwargs) -> _T:
3254+
print("Function was called")
32513255
return f(*args, **kwargs)
32523256
return inner
32533257
```
@@ -3352,19 +3356,6 @@ def generate_foo_scores(foo: set[str]) -> list[float]:
33523356
...
33533357
```
33543358
3355-
NOTE: Users of [Apache Beam](https://github.com/apache/beam/issues/23366) should
3356-
continue to import parametric containers from `typing`.
3357-
3358-
```python
3359-
from typing import Set, List
3360-
3361-
# Only use this older style if you are required to by introspection
3362-
# code such as Apache Beam that has not yet been updated for PEP-585,
3363-
# or if your code needs to run on Python versions earlier than 3.9.
3364-
def generate_foo_scores(foo: Set[str]) -> List[float]:
3365-
...
3366-
```
3367-
33683359
<a id="s3.19.13-conditional-imports"></a>
33693360
<a id="31913-conditional-imports"></a>
33703361
@@ -3471,14 +3462,20 @@ def get_names(employee_ids: Sequence[_T]) -> Mapping[_T, str]:
34713462
*BE CONSISTENT*.
34723463
34733464
If you're editing code, take a few minutes to look at the code around you and
3474-
determine its style. If they use spaces around all their arithmetic operators,
3475-
you should too. If their comments have little boxes of hash marks around them,
3476-
make your comments have little boxes of hash marks around them too.
3465+
determine its style. If they use `_idx` suffixes in index variable names, you
3466+
should too. If their comments have little boxes of hash marks around them, make
3467+
your comments have little boxes of hash marks around them too.
34773468
34783469
The point of having style guidelines is to have a common vocabulary of coding so
34793470
people can concentrate on what you're saying rather than on how you're saying
34803471
it. We present global style rules here so people know the vocabulary, but local
34813472
style is also important. If code you add to a file looks drastically different
34823473
from the existing code around it, it throws readers out of their rhythm when
3483-
they go to read it. Avoid this.
3474+
they go to read it.
3475+
3476+
However, there are limits to consistency. It applies more heavily locally and on
3477+
choices unspecified by the global style. Consistency should not generally be
3478+
used as a justification to do things in an old style without considering the
3479+
benefits of the new style, or the tendency of the codebase to converge on newer
3480+
styles over time.
34843481

0 commit comments

Comments
 (0)