mirror of
https://github.com/google/styleguide.git
synced 2024-03-22 13:11:43 +08:00
Project import generated by Copybara.
PiperOrigin-RevId: 287589810
This commit is contained in:
parent
26470f9ccb
commit
b88c6a1b42
|
@ -1,3 +1,17 @@
|
||||||
|
" Copyright 2019 Google LLC
|
||||||
|
"
|
||||||
|
" Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
" you may not use this file except in compliance with the License.
|
||||||
|
" You may obtain a copy of the License at
|
||||||
|
"
|
||||||
|
" https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
"
|
||||||
|
" Unless required by applicable law or agreed to in writing, software
|
||||||
|
" distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
" See the License for the specific language governing permissions and
|
||||||
|
" limitations under the License.
|
||||||
|
|
||||||
" Indent Python in the Google way.
|
" Indent Python in the Google way.
|
||||||
|
|
||||||
setlocal indentexpr=GetGooglePythonIndent(v:lnum)
|
setlocal indentexpr=GetGooglePythonIndent(v:lnum)
|
||||||
|
|
29
pyguide.md
29
pyguide.md
|
@ -585,10 +585,10 @@ No:
|
||||||
result = [(x, y) for x in range(10) for y in range(5) if x * y > 10]
|
result = [(x, y) for x in range(10) for y in range(5) if x * y > 10]
|
||||||
|
|
||||||
return ((x, y, z)
|
return ((x, y, z)
|
||||||
for x in xrange(5)
|
for x in range(5)
|
||||||
for y in xrange(5)
|
for y in range(5)
|
||||||
if x != y
|
if x != y
|
||||||
for z in xrange(5)
|
for z in range(5)
|
||||||
if y != z)
|
if y != z)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -886,6 +886,8 @@ No: def foo(a, b=time.time()): # The time the module was loaded???
|
||||||
...
|
...
|
||||||
No: def foo(a, b=FLAGS.my_thing): # sys.argv has not yet been parsed...
|
No: def foo(a, b=FLAGS.my_thing): # sys.argv has not yet been parsed...
|
||||||
...
|
...
|
||||||
|
No: def foo(a, b: Mapping = {}): # Could still get passed to unchecked code
|
||||||
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
<a id="s2.13-properties"></a>
|
<a id="s2.13-properties"></a>
|
||||||
|
@ -2113,7 +2115,7 @@ knows Python (though not what you're trying to do) better than you do.
|
||||||
<a id="grammar"></a>
|
<a id="grammar"></a>
|
||||||
|
|
||||||
<a id="punctuation-spelling-grammar"></a>
|
<a id="punctuation-spelling-grammar"></a>
|
||||||
#### 3.8.6 Punctuation, Spelling and Grammar
|
#### 3.8.6 Punctuation, Spelling, and Grammar
|
||||||
|
|
||||||
Pay attention to punctuation, spelling, and grammar; it is easier to read
|
Pay attention to punctuation, spelling, and grammar; it is easier to read
|
||||||
well-written comments than badly written ones.
|
well-written comments than badly written ones.
|
||||||
|
@ -2965,17 +2967,17 @@ specify its type in a couple ways.
|
||||||
[*Type Comments:*](#type-comments)
|
[*Type Comments:*](#type-comments)
|
||||||
: Use a `# type:` comment on the end of the line
|
: Use a `# type:` comment on the end of the line
|
||||||
|
|
||||||
```python
|
```python
|
||||||
a = SomeUndecoratedFunction() # type: Foo
|
a = SomeUndecoratedFunction() # type: Foo
|
||||||
```
|
```
|
||||||
|
|
||||||
[*Annotated Assignments*](#annotated-assignments)
|
[*Annotated Assignments*](#annotated-assignments)
|
||||||
: Use a colon and type between the variable name and value, as with function
|
: Use a colon and type between the variable name and value, as with function
|
||||||
arguments.
|
arguments.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
a: Foo = SomeUndecoratedFunction()
|
a: Foo = SomeUndecoratedFunction()
|
||||||
```
|
```
|
||||||
|
|
||||||
<a id="s3.19.9-tuples"></a>
|
<a id="s3.19.9-tuples"></a>
|
||||||
<a id="3199-tuples-vs-lists"></a>
|
<a id="3199-tuples-vs-lists"></a>
|
||||||
|
@ -3136,16 +3138,15 @@ imports should be preferred.
|
||||||
Imports that are needed only for type annotations can be placed within an
|
Imports that are needed only for type annotations can be placed within an
|
||||||
`if TYPE_CHECKING:` block.
|
`if TYPE_CHECKING:` block.
|
||||||
|
|
||||||
- Conditionally imported types need to be referenced as strings, to be
|
- Conditionally imported types need to be referenced as strings, to be forward
|
||||||
forward compatible with Python 3.6 where the annotation expressions are
|
compatible with Python 3.6 where the annotation expressions are actually
|
||||||
actually evaluated.
|
evaluated.
|
||||||
- Only entities that are used solely for typing should be defined here; this
|
- Only entities that are used solely for typing should be defined here; this
|
||||||
includes aliases. Otherwise it will be a runtime error, as the module will
|
includes aliases. Otherwise it will be a runtime error, as the module will
|
||||||
not be imported at runtime.
|
not be imported at runtime.
|
||||||
- The block should be right after all the normal imports.
|
- The block should be right after all the normal imports.
|
||||||
- There should be no empty lines in the typing imports list.
|
- There should be no empty lines in the typing imports list.
|
||||||
- Sort this list as if it were a regular imports list.
|
- Sort this list as if it were a regular imports list.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import typing
|
import typing
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user