You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Elegantly specifies some transformation on a method; the transformation might
931
931
eliminate some repetitive code, enforce invariants, etc.
932
932
933
-
<a id="s2.17.3-cons">
933
+
<a id="s2.17.3-cons"></a>
934
934
#### 2.17.3 Cons
935
935
936
936
Decorators can perform arbitrary operations on a function's arguments or return
937
937
values, resulting in surprising implicit behavior. Additionally, decorators
938
938
execute at import time. Failures in decorator code are pretty much impossible to
939
939
recover from.
940
940
941
-
<a id="s2.17.4-decision">
941
+
<a id="s2.17.4-decision"></a>
942
942
#### 2.17.4 Decision
943
943
944
944
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
984
984
985
985
Avoid these features.
986
986
987
-
<a id="s2.19.1-definition">
987
+
<a id="s2.19.1-definition"></a>
988
988
#### 2.19.1 Definition
989
989
990
990
Python is an extremely flexible language and gives you many fancy features such
991
991
as custom metaclasses, access to bytecode, on-the-fly compilation, dynamic
992
992
inheritance, object reparenting, import hacks, reflection, modification of
993
993
system internals, etc.
994
994
995
-
<a id="s2.19.2-pros">
995
+
<a id="s2.19.2-pros"></a>
996
996
#### 2.19.2 Pros
997
997
998
998
These are powerful language features. They can make your code more compact.
999
999
1000
-
<a id="s2.19.3-cons">
1000
+
<a id="s2.19.3-cons"></a>
1001
1001
#### 2.19.3 Cons
1002
1002
1003
1003
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),
1006
1006
but when revisiting the code, it tends to be more difficult than code that is
1007
1007
longer but is straightforward.
1008
1008
1009
-
<a id="s2.19.4-decision">
1009
+
<a id="s2.19.4-decision"></a>
1010
1010
#### 2.19.4 Decision
1011
1011
1012
1012
Avoid these features in your code.
@@ -1020,29 +1020,29 @@ to use (for example, `abc.ABCMeta`, `collections.namedtuple`, and `enum`).
1020
1020
1021
1021
Python 3is here. While not every project is ready to use it yet, all code should be written with an eye towards the future.
1022
1022
1023
-
<a id="s2.20.1-definition">
1023
+
<a id="s2.20.1-definition"></a>
1024
1024
#### 2.20.1 Definition
1025
1025
1026
1026
Python 3is a significant change in the Python language. While existing code is
1027
1027
often written with2.7in mind there are some simple things to do to make code
1028
1028
more explicit about its intentions and thus better prepared for use under Python
1029
1029
3 without modification.
1030
1030
1031
-
<a id="s2.20.2-pros">
1031
+
<a id="s2.20.2-pros"></a>
1032
1032
#### 2.20.2 Pros
1033
1033
1034
1034
Code written with Python 3in mind is more explicit and easier to get running
1035
1035
under Python 3 once all of the dependencies of your project are ready.
1036
1036
1037
-
<a id="s2.20.3-cons">
1037
+
<a id="s2.20.3-cons"></a>
1038
1038
#### 2.20.3 Cons
1039
1039
1040
1040
Some people find the additional boilerplate to be ugly. Others say "but I don't
1041
1041
use that feature in this file" and want to clean-up. Please don't. It is better
1042
1042
to always have the future imports inall files so that they are not forgotten
1043
1043
during later edits when someone starts using such a feature.
1044
1044
1045
-
<a id="s2.20.4-decision">
1045
+
<a id="s2.20.4-decision"></a>
1046
1046
#### 2.20.4 Decision
1047
1047
1048
1048
##### from \_\_future\_\_ imports
@@ -1090,7 +1090,7 @@ annotations should be in the source. Use pyi files for third-party or extension
1090
1090
modules.
1091
1091
1092
1092
1093
-
<a id="s2.21.1-definition">
1093
+
<a id="s2.21.1-definition"></a>
1094
1094
#### 2.21.1 Definition
1095
1095
1096
1096
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:
1106
1106
a= SomeFunc() # type:SomeType
1107
1107
```
1108
1108
1109
-
<a id="s2.21.2-pros">
1109
+
<a id="s2.21.2-pros"></a>
1110
1110
#### 2.21.2 Pros
1111
1111
1112
1112
Type annotations improve the readability and maintainability of your code. The
1113
1113
type checker will convert many runtime errors to build-time errors, andreduce
1114
1114
your ability to use [Power Features](#power-features).
1115
1115
1116
-
<a id="s2.21.3-cons">
1116
+
<a id="s2.21.3-cons"></a>
1117
1117
#### 2.21.3 Cons
1118
1118
1119
1119
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)
1120
1120
may reduce your ability to use [Power Features](#power-features).
1121
1121
1122
-
<a id="s2.21.4-decision">
1122
+
<a id="s2.21.4-decision"></a>
1123
1123
#### 2.21.4 Decision
1124
1124
1125
1125
This highly depends on the complexity of your project. Give it a try.
0 commit comments