Skip to content

Commit 9ea26f7

Browse files
committed
Fix markdown headings not rendering
1 parent 89be4df commit 9ea26f7

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

pyguide.md

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -477,26 +477,26 @@ No: for key in adict.keys(): ...
477477
478478
Use generators as needed.
479479
480-
<a id="s2.9.1-definition">
480+
<a id="s2.9.1-definition"></a>
481481
#### 2.9.1 Definition
482482
483483
A generator function returns an iterator that yields a value each time it
484484
executes a yield statement. After it yields a value, the runtime state of the
485485
generator function is suspended until the next value is needed.
486486
487-
<a id="s2.9.2-pros">
487+
<a id="s2.9.2-pros"></a>
488488
#### 2.9.2 Pros
489489
490490
Simpler code, because the state of local variables and control flow are
491491
preserved for each call. A generator uses less memory than a function that
492492
creates an entire list of values at once.
493493
494-
<a id="s2.9.3-cons">
494+
<a id="s2.9.3-cons"></a>
495495
#### 2.9.3 Cons
496496
497497
None.
498498
499-
<a id="s2.9.4-decision">
499+
<a id="s2.9.4-decision"></a>
500500
#### 2.9.4 Decision
501501
502502
Fine. Use "Yields:" rather than "Returns:" in the docstring for generator
@@ -508,26 +508,26 @@ functions.
508508
509509
Okay for one-liners.
510510
511-
<a id="s2.10.1-definition">
511+
<a id="s2.10.1-definition"></a>
512512
#### 2.10.1 Definition
513513
514514
Lambdas define anonymous functions in an expression, as opposed to a statement.
515515
They are often used to define callbacks or operators for higher-order functions
516516
like `map()` and `filter()`.
517517
518-
<a id="s2.10.2-pros">
518+
<a id="s2.10.2-pros"></a>
519519
#### 2.10.2 Pros
520520
521521
Convenient.
522522
523-
<a id="s2.10.3-cons">
523+
<a id="s2.10.3-cons"></a>
524524
#### 2.10.3 Cons
525525
526526
Harder to read and debug than local functions. The lack of names means stack
527527
traces are more difficult to understand. Expressiveness is limited because the
528528
function may only contain an expression.
529529
530-
<a id="s2.10.4-decision">
530+
<a id="s2.10.4-decision"></a>
531531
#### 2.10.4 Decision
532532
533533
Okay to use them for one-liners. If the code inside the lambda function is any
@@ -544,25 +544,25 @@ module instead of lambda functions. For example, prefer `operator.mul` to
544544
545545
Okay for one-liners.
546546
547-
<a id="s2.11.1-definition">
547+
<a id="s2.11.1-definition"></a>
548548
#### 2.11.1 Definition
549549
550550
Conditional expressions (sometimes called a “ternary operator”) are mechanisms
551551
that provide a shorter syntax for if statements. For example:
552552
`x = 1 if cond else 2`.
553553
554-
<a id="s2.11.2-pros">
554+
<a id="s2.11.2-pros"></a>
555555
#### 2.11.2 Pros
556556
557557
Shorter and more convenient than an if statement.
558558
559-
<a id="s2.11.3-cons">
559+
<a id="s2.11.3-cons"></a>
560560
#### 2.11.3 Cons
561561
562562
May be harder to read than an if statement. The condition may be difficult to
563563
locate if the expression is long.
564564
565-
<a id="s2.11.4-decision">
565+
<a id="s2.11.4-decision"></a>
566566
#### 2.11.4 Decision
567567
568568
Okay to use for one-liners. In other cases prefer to use a complete if
@@ -574,15 +574,15 @@ statement.
574574
575575
Okay in most cases.
576576
577-
<a id="s2.12.1-definition">
577+
<a id="s2.12.1-definition"></a>
578578
#### 2.12.1 Definition
579579
580580
You can specify values for variables at the end of a function's parameter list,
581581
e.g., `def foo(a, b=0):`. If `foo` is called with only one argument,
582582
`b` is set to 0. If it is called with two arguments, `b` has the value of the
583583
second argument.
584584
585-
<a id="s2.12.2-pros">
585+
<a id="s2.12.2-pros"></a>
586586
#### 2.12.2 Pros
587587
588588
Often you have a function that uses lots of default values, but-rarely-you want
@@ -591,15 +591,15 @@ this, without having to define lots of functions for the rare exceptions. Also,
591591
Python does not support overloaded methods/functions and default arguments are
592592
an easy way of "faking" the overloading behavior.
593593
594-
<a id="s2.12.3-cons">
594+
<a id="s2.12.3-cons"></a>
595595
#### 2.12.3 Cons
596596
597597
Default arguments are evaluated once at module load time. This may cause
598598
problems if the argument is a mutable object such as a list or a dictionary. If
599599
the function modifies the object (e.g., by appending an item to a list), the
600600
default value is modified.
601601
602-
<a id="s2.12.4-decision">
602+
<a id="s2.12.4-decision"></a>
603603
#### 2.12.4 Decision
604604
605605
Okay to use with the following caveat:
@@ -632,13 +632,13 @@ No: def foo(a, b=FLAGS.my_thing): # sys.argv has not yet been parsed...
632632
Use properties for accessing or setting data where you would normally have used
633633
simple, lightweight accessor or setter methods.
634634
635-
<a id="s2.13.1-definition">
635+
<a id="s2.13.1-definition"></a>
636636
#### 2.13.1 Definition
637637
638638
A way to wrap method calls for getting and setting an attribute as a standard
639639
attribute access when the computation is lightweight.
640640
641-
<a id="s2.13.2-pros">
641+
<a id="s2.13.2-pros"></a>
642642
#### 2.13.2 Pros
643643
644644
Readability is increased by eliminating explicit get and set method calls for
@@ -648,13 +648,13 @@ properties bypasses needing trivial accessor methods when a direct variable
648648
access is reasonable. This also allows accessor methods to be added in the
649649
future without breaking the interface.
650650
651-
<a id="s2.13.3-cons">
651+
<a id="s2.13.3-cons"></a>
652652
#### 2.13.3 Cons
653653
654654
Must inherit from `object` in Python 2. Can hide side-effects much like operator
655655
overloading. Can be confusing for subclasses.
656656
657-
<a id="s2.13.4-decision">
657+
<a id="s2.13.4-decision"></a>
658658
#### 2.13.4 Decision
659659
660660
Use properties in new code to access or set data where you would normally have
@@ -716,25 +716,25 @@ Yes: import math
716716
717717
Use the "implicit" false if at all possible.
718718
719-
<a id="s2.14.1-definition">
719+
<a id="s2.14.1-definition"></a>
720720
#### 2.14.1 Definition
721721
722722
Python evaluates certain values as `False` when in a boolean context. A quick
723723
"rule of thumb" is that all "empty" values are considered false, so
724724
`0, None, [], {}, ''` all evaluate as false in a boolean context.
725725
726-
<a id="s2.14.2-pros">
726+
<a id="s2.14.2-pros"></a>
727727
#### 2.14.2 Pros
728728
729729
Conditions using Python booleans are easier to read and less error-prone. In
730730
most cases, they're also faster.
731731
732-
<a id="s2.14.3-cons">
732+
<a id="s2.14.3-cons"></a>
733733
#### 2.14.3 Cons
734734
735735
May look strange to C/C++ developers.
736736
737-
<a id="s2.14.4-decision">
737+
<a id="s2.14.4-decision"></a>
738738
#### 2.14.4 Decision
739739
740740
Use the "implicit" false if at all possible, e.g., `if foo:` rather than
@@ -801,13 +801,13 @@ call syntax instead of `apply`. Use list comprehensions and `for` loops instead
801801
of `filter` and `map` when the function argument would have been an inlined
802802
lambda anyway. Use `for` loops instead of `reduce`.
803803
804-
<a id="s2.15.1-definition">
804+
<a id="s2.15.1-definition"></a>
805805
#### 2.15.1 Definition
806806
807807
Current versions of Python provide alternative constructs that people find
808808
generally preferable.
809809
810-
<a id="s2.15.2-decision">
810+
<a id="s2.15.2-decision"></a>
811811
#### 2.15.2 Decision
812812
813813
We do not use any Python version which does not support these features, so there
@@ -837,7 +837,7 @@ No: words = string.split(foo, ':')
837837
838838
Okay to use.
839839
840-
<a id="s2.16.1-definition">
840+
<a id="s2.16.1-definition"></a>
841841
#### 2.16.1 Definition
842842
843843
A nested Python function can refer to variables defined in enclosing functions,
@@ -858,13 +858,13 @@ def get_adder(summand1):
858858
return adder
859859
```
860860
861-
<a id="s2.16.2-pros">
861+
<a id="s2.16.2-pros"></a>
862862
#### 2.16.2 Pros
863863
864864
Often results in clearer, more elegant code. Especially comforting to
865865
experienced Lisp and Scheme (and Haskell and ML and ...) programmers.
866866
867-
<a id="s2.16.3-cons">
867+
<a id="s2.16.3-cons"></a>
868868
#### 2.16.3 Cons
869869
870870
Can lead to confusing bugs. Such as this example based on
@@ -886,7 +886,7 @@ def foo(x):
886886
So `foo([1, 2, 3])` will print `1 2 3 3`, not `1 2 3
887887
4`.
888888
889-
<a id="s2.16.4-decision">
889+
<a id="s2.16.4-decision"></a>
890890
#### 2.16.4 Decision
891891
892892
Okay to use.
@@ -898,7 +898,7 @@ Okay to use.
898898
Use decorators judiciously when there is a clear advantage. Avoid
899899
`@staticmethod` and limit use of `@classmethod`.
900900
901-
<a id="s2.17.1-definition">
901+
<a id="s2.17.1-definition"></a>
902902
#### 2.17.1 Definition
903903
904904
[Decorators for Functions and
@@ -924,21 +924,21 @@ class C(object):
924924
Methodmethod = MyDecoratormy_decorator(Methodmethod)
925925
```
926926
927-
<a id="s2.17.2-pros">
927+
<a id="s2.17.2-pros"></a>
928928
#### 2.17.2 Pros
929929
930930
Elegantly specifies some transformation on a method; the transformation might
931931
eliminate some repetitive code, enforce invariants, etc.
932932
933-
<a id="s2.17.3-cons">
933+
<a id="s2.17.3-cons"></a>
934934
#### 2.17.3 Cons
935935
936936
Decorators can perform arbitrary operations on a function's arguments or return
937937
values, resulting in surprising implicit behavior. Additionally, decorators
938938
execute at import time. Failures in decorator code are pretty much impossible to
939939
recover from.
940940
941-
<a id="s2.17.4-decision">
941+
<a id="s2.17.4-decision"></a>
942942
#### 2.17.4 Decision
943943
944944
Use decorators judiciously when there is a clear advantage. Decorators should
@@ -984,20 +984,20 @@ primitives. Learn about the proper use of condition variables so you can use
984984
985985
Avoid these features.
986986
987-
<a id="s2.19.1-definition">
987+
<a id="s2.19.1-definition"></a>
988988
#### 2.19.1 Definition
989989
990990
Python is an extremely flexible language and gives you many fancy features such
991991
as custom metaclasses, access to bytecode, on-the-fly compilation, dynamic
992992
inheritance, object reparenting, import hacks, reflection, modification of
993993
system internals, etc.
994994
995-
<a id="s2.19.2-pros">
995+
<a id="s2.19.2-pros"></a>
996996
#### 2.19.2 Pros
997997
998998
These are powerful language features. They can make your code more compact.
999999
1000-
<a id="s2.19.3-cons">
1000+
<a id="s2.19.3-cons"></a>
10011001
#### 2.19.3 Cons
10021002
10031003
It's very tempting to use these "cool" features when they're not absolutely
@@ -1006,7 +1006,7 @@ features underneath. It doesn't seem that way at first (to the original author),
10061006
but when revisiting the code, it tends to be more difficult than code that is
10071007
longer but is straightforward.
10081008
1009-
<a id="s2.19.4-decision">
1009+
<a id="s2.19.4-decision"></a>
10101010
#### 2.19.4 Decision
10111011
10121012
Avoid these features in your code.
@@ -1020,29 +1020,29 @@ to use (for example, `abc.ABCMeta`, `collections.namedtuple`, and `enum`).
10201020
10211021
Python 3 is here. While not every project is ready to use it yet, all code should be written with an eye towards the future.
10221022
1023-
<a id="s2.20.1-definition">
1023+
<a id="s2.20.1-definition"></a>
10241024
#### 2.20.1 Definition
10251025
10261026
Python 3 is a significant change in the Python language. While existing code is
10271027
often written with 2.7 in mind there are some simple things to do to make code
10281028
more explicit about its intentions and thus better prepared for use under Python
10291029
3 without modification.
10301030
1031-
<a id="s2.20.2-pros">
1031+
<a id="s2.20.2-pros"></a>
10321032
#### 2.20.2 Pros
10331033
10341034
Code written with Python 3 in mind is more explicit and easier to get running
10351035
under Python 3 once all of the dependencies of your project are ready.
10361036
1037-
<a id="s2.20.3-cons">
1037+
<a id="s2.20.3-cons"></a>
10381038
#### 2.20.3 Cons
10391039
10401040
Some people find the additional boilerplate to be ugly. Others say "but I don't
10411041
use that feature in this file" and want to clean-up. Please don't. It is better
10421042
to always have the future imports in all files so that they are not forgotten
10431043
during later edits when someone starts using such a feature.
10441044
1045-
<a id="s2.20.4-decision">
1045+
<a id="s2.20.4-decision"></a>
10461046
#### 2.20.4 Decision
10471047
10481048
##### from \_\_future\_\_ imports
@@ -1090,7 +1090,7 @@ annotations should be in the source. Use pyi files for third-party or extension
10901090
modules.
10911091
10921092
1093-
<a id="s2.21.1-definition">
1093+
<a id="s2.21.1-definition"></a>
10941094
#### 2.21.1 Definition
10951095
10961096
Type annotations (or "type hints") are for function or method arguments and
@@ -1106,20 +1106,20 @@ You can also declare the type of a variable using a special comment:
11061106
a = SomeFunc() # type: SomeType
11071107
```
11081108
1109-
<a id="s2.21.2-pros">
1109+
<a id="s2.21.2-pros"></a>
11101110
#### 2.21.2 Pros
11111111
11121112
Type annotations improve the readability and maintainability of your code. The
11131113
type checker will convert many runtime errors to build-time errors, and reduce
11141114
your ability to use [Power Features](#power-features).
11151115
1116-
<a id="s2.21.3-cons">
1116+
<a id="s2.21.3-cons"></a>
11171117
#### 2.21.3 Cons
11181118
11191119
You will have to keep the type declarations up to date. You might see type errors that you think are valid code. Use of a [type checker](https://github.com/google/pytype)
11201120
may reduce your ability to use [Power Features](#power-features).
11211121
1122-
<a id="s2.21.4-decision">
1122+
<a id="s2.21.4-decision"></a>
11231123
#### 2.21.4 Decision
11241124
11251125
This highly depends on the complexity of your project. Give it a try.

0 commit comments

Comments
 (0)