Skip to content

Commit 3714aa1

Browse files
geryogamgvanrossum
authored andcommitted
PEP 8: Fix inconsistent use of line breaks, case and indentation (#664)
1 parent 7eb19d4 commit 3714aa1

File tree

1 file changed

+36
-51
lines changed

1 file changed

+36
-51
lines changed

pep-0008.txt

+36-51
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Some other good reasons to ignore a particular guideline:
6868
Python that don't support the feature recommended by the style guide.
6969

7070

71-
Code lay-out
71+
Code Lay-out
7272
============
7373

7474
Indentation
@@ -179,7 +179,6 @@ starts the multiline construct, as in::
179179
'd', 'e', 'f',
180180
)
181181

182-
183182
Tabs or Spaces?
184183
---------------
185184

@@ -198,7 +197,6 @@ the ``-t`` option, it issues warnings about code that illegally mixes
198197
tabs and spaces. When using ``-tt`` these warnings become errors.
199198
These options are highly recommended!
200199

201-
202200
Maximum Line Length
203201
-------------------
204202

@@ -249,7 +247,6 @@ Another such case is with ``assert`` statements.
249247

250248
Make sure to indent the continued line appropriately.
251249

252-
253250
Should a Line Break Before or After a Binary Operator?
254251
------------------------------------------------------
255252

@@ -287,7 +284,6 @@ In Python code, it is permissible to break before or after a binary
287284
operator, as long as the convention is consistent locally. For new
288285
code Knuth's style is suggested.
289286

290-
291287
Blank Lines
292288
-----------
293289

@@ -309,7 +305,6 @@ you may use them to separate pages of related sections of your file.
309305
Note, some editors and web-based code viewers may not recognize
310306
control-L as a form feed and will show another glyph in its place.
311307

312-
313308
Source File Encoding
314309
--------------------
315310

@@ -339,11 +334,10 @@ a transliteration of their names in this character set.
339334
Open source projects with a global audience are encouraged to adopt a
340335
similar policy.
341336

342-
343337
Imports
344338
-------
345339

346-
- Imports should usually be on separate lines, e.g.::
340+
- Imports should usually be on separate lines::
347341

348342
Yes: import os
349343
import sys
@@ -370,16 +364,16 @@ Imports
370364
messages) if the import system is incorrectly configured (such as
371365
when a directory inside a package ends up on ``sys.path``)::
372366

373-
import mypkg.sibling
374-
from mypkg import sibling
375-
from mypkg.sibling import example
367+
import mypkg.sibling
368+
from mypkg import sibling
369+
from mypkg.sibling import example
376370

377371
However, explicit relative imports are an acceptable alternative to
378372
absolute imports, especially when dealing with complex package layouts
379373
where using absolute imports would be unnecessarily verbose::
380374

381-
from . import sibling
382-
from .sibling import example
375+
from . import sibling
376+
from .sibling import example
383377

384378
Standard library code should avoid complex package layouts and always
385379
use absolute imports.
@@ -393,7 +387,7 @@ Imports
393387
from myclass import MyClass
394388
from foo.bar.yourclass import YourClass
395389

396-
If this spelling causes local name clashes, then spell them ::
390+
If this spelling causes local name clashes, then spell them explicitly::
397391

398392
import myclass
399393
import foo.bar.yourclass
@@ -412,18 +406,15 @@ Imports
412406
When republishing names this way, the guidelines below regarding
413407
public and internal interfaces still apply.
414408

415-
416-
Module level dunder names
409+
Module Level Dunder Names
417410
-------------------------
418411

419412
Module level "dunders" (i.e. names with two leading and two trailing
420413
underscores) such as ``__all__``, ``__author__``, ``__version__``,
421414
etc. should be placed after the module docstring but before any import
422415
statements *except* ``from __future__`` imports. Python mandates that
423416
future-imports must appear in the module before any other code except
424-
docstrings.
425-
426-
For example::
417+
docstrings::
427418

428419
"""This is the example module.
429420

@@ -524,7 +515,6 @@ Avoid extraneous whitespace in the following situations:
524515
y = 2
525516
long_variable = 3
526517

527-
528518
Other Recommendations
529519
---------------------
530520

@@ -642,6 +632,7 @@ Other Recommendations
642632

643633
if foo == 'blah': one(); two(); three()
644634

635+
645636
When to Use Trailing Commas
646637
===========================
647638

@@ -748,7 +739,7 @@ Conventions for writing good documentation strings
748739

749740
- PEP 257 describes good docstring conventions. Note that most
750741
importantly, the ``"""`` that ends a multiline docstring should be
751-
on a line by itself, e.g.::
742+
on a line by itself::
752743

753744
"""Return a foobang
754745

@@ -888,12 +879,12 @@ Type Variable Names
888879
Names of type variables introduced in PEP 484 should normally use CapWords
889880
preferring short names: ``T``, ``AnyStr``, ``Num``. It is recommended to add
890881
suffixes ``_co`` or ``_contra`` to the variables used to declare covariant
891-
or contravariant behavior correspondingly. Examples::
882+
or contravariant behavior correspondingly::
892883

893-
from typing import TypeVar
884+
from typing import TypeVar
894885

895-
VT_co = TypeVar('VT_co', covariant=True)
896-
KT_contra = TypeVar('KT_contra', contravariant=True)
886+
VT_co = TypeVar('VT_co', covariant=True)
887+
KT_contra = TypeVar('KT_contra', contravariant=True)
897888

898889
Exception Names
899890
~~~~~~~~~~~~~~~
@@ -966,7 +957,7 @@ Constants are usually defined on a module level and written in all
966957
capital letters with underscores separating words. Examples include
967958
``MAX_OVERFLOW`` and ``TOTAL``.
968959

969-
Designing for inheritance
960+
Designing for Inheritance
970961
~~~~~~~~~~~~~~~~~~~~~~~~~
971962

972963
Always decide whether a class's methods and instance variables
@@ -1041,7 +1032,6 @@ With this in mind, here are the Pythonic guidelines:
10411032
need to avoid accidental name clashes with potential use by
10421033
advanced callers.
10431034

1044-
10451035
Public and Internal Interfaces
10461036
------------------------------
10471037

@@ -1180,9 +1170,7 @@ Programming Recommendations
11801170
continuation characters thanks to the containing parentheses.
11811171

11821172
- When catching exceptions, mention specific exceptions whenever
1183-
possible instead of using a bare ``except:`` clause.
1184-
1185-
For example, use::
1173+
possible instead of using a bare ``except:`` clause::
11861174

11871175
try:
11881176
import platform_specific_module
@@ -1250,17 +1238,16 @@ Programming Recommendations
12501238

12511239
- Context managers should be invoked through separate functions or methods
12521240
whenever they do something other than acquire and release resources.
1253-
For example:
12541241

12551242
Yes::
12561243

1257-
with conn.begin_transaction():
1258-
do_stuff_in_transaction(conn)
1244+
with conn.begin_transaction():
1245+
do_stuff_in_transaction(conn)
12591246

12601247
No::
12611248

1262-
with conn:
1263-
do_stuff_in_transaction(conn)
1249+
with conn:
1250+
do_stuff_in_transaction(conn)
12641251

12651252
The latter example doesn't provide any information to indicate that
12661253
the ``__enter__`` and ``__exit__`` methods are doing something other
@@ -1307,8 +1294,7 @@ Programming Recommendations
13071294
- Use ``''.startswith()`` and ``''.endswith()`` instead of string
13081295
slicing to check for prefixes or suffixes.
13091296

1310-
startswith() and endswith() are cleaner and less error prone. For
1311-
example::
1297+
startswith() and endswith() are cleaner and less error prone::
13121298

13131299
Yes: if foo.startswith('bar'):
13141300
No: if foo[:3] == 'bar':
@@ -1328,16 +1314,16 @@ Programming Recommendations
13281314

13291315
Note that in Python 3, ``unicode`` and ``basestring`` no longer exist
13301316
(there is only ``str``) and a bytes object is no longer a kind of
1331-
string (it is a sequence of integers instead)
1317+
string (it is a sequence of integers instead).
13321318

13331319
- For sequences, (strings, lists, tuples), use the fact that empty
13341320
sequences are false. ::
13351321

13361322
Yes: if not seq:
13371323
if seq:
13381324

1339-
No: if len(seq):
1340-
if not len(seq):
1325+
No: if len(seq):
1326+
if not len(seq):
13411327

13421328
- Don't write string literals that rely on significant trailing
13431329
whitespace. Such trailing whitespace is visually indistinguishable
@@ -1375,7 +1361,7 @@ annotations are changing.
13751361
- For code that wants to make a different use of function annotations
13761362
it is recommended to put a comment of the form::
13771363

1378-
# type: ignore
1364+
# type: ignore
13791365

13801366
near the top of the file; this tells type checker to ignore all
13811367
annotations. (More fine-grained ways of disabling complaints from
@@ -1397,7 +1383,7 @@ annotations are changing.
13971383
can be added in the form of comments. See the relevant section of
13981384
PEP 484 [6]_.
13991385

1400-
Variable annotations
1386+
Variable Annotations
14011387
--------------------
14021388

14031389
PEP 526 introduced variable annotations. The style recommendations for them are
@@ -1413,19 +1399,19 @@ similar to those on function annotations described above:
14131399

14141400
- Yes::
14151401

1416-
code: int
1402+
code: int
14171403

1418-
class Point:
1419-
coords: Tuple[int, int]
1420-
label: str = '<unknown>'
1404+
class Point:
1405+
coords: Tuple[int, int]
1406+
label: str = '<unknown>'
14211407

14221408
- No::
14231409

1424-
code:int # No space after colon
1425-
code : int # Space before colon
1410+
code:int # No space after colon
1411+
code : int # Space before colon
14261412

1427-
class Test:
1428-
result: int=0 # No spaces around equality sign
1413+
class Test:
1414+
result: int=0 # No spaces around equality sign
14291415

14301416
- Although the PEP 526 is accepted for Python 3.6, the variable annotation
14311417
syntax is the preferred syntax for stub files on all versions of Python
@@ -1460,7 +1446,6 @@ References
14601446
https://www.python.org/dev/peps/pep-0484/#suggested-syntax-for-python-2-7-and-straddling-code
14611447

14621448

1463-
14641449
Copyright
14651450
=========
14661451

0 commit comments

Comments
 (0)