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
Copy file name to clipboardExpand all lines: docs/writing/style.rst
+14-14Lines changed: 14 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -10,8 +10,8 @@ recognised fact that code is read much more often than it is written.
10
10
One reason for Python code to be easily read and understood is its relatively
11
11
complete set of Code Style guidelines and "Pythonic" idioms.
12
12
13
-
Moreover, when a veteran Python developer (a Pythonista) point to some
14
-
parts of a code and say it is not "Pythonic", it usually means that these lines
13
+
Moreover, when a veteran Python developer (a Pythonista) points to portions of code
14
+
and says they are not "Pythonic", it usually means that these lines
15
15
of code do not follow the common guidelines and fail to express the intent in
16
16
what is considered the best (hear: most readable) way.
17
17
@@ -89,7 +89,7 @@ Arguments can be passed to functions in four different ways.
89
89
simplest form of arguments and they can be used for the few function arguments
90
90
that are fully part of the functions meaning and their order is natural. For
91
91
instance, in ``send(message, recipient)`` or ``point(x, y)`` the user of the
92
-
function has no difficulty to remember that those two function require two
92
+
function has no difficulty remembering that those two functions require two
93
93
arguments, and in which order.
94
94
95
95
In those two cases, it is possible to use argument names when calling the functions
@@ -103,7 +103,7 @@ used for optional parameters sent to the function. When a function has more than
103
103
two or three positional parameters, its signature will be more difficult to remember
104
104
and using keyword argument with default values is helpful. For instance, a more
105
105
complete ``send`` function could be defined as ``send(message, to, cc=None, bcc=None)``.
106
-
Here ``cc`` and ``bcc`` are optional, and evaluate to ``None`` when the are not
106
+
Here ``cc`` and ``bcc`` are optional, and evaluate to ``None`` when they are not
107
107
passed another value.
108
108
109
109
Calling a function with keyword arguments can be done in multiple ways in Python,
@@ -189,18 +189,18 @@ As seen above, Python allows many tricks, and some of them are potentially
189
189
dangerous. A good example is that any client code can override an object's
190
190
properties and methods: there is no "private" keyword in Python. This
191
191
philosophy, very different from highly defensive languages like Java, which
192
-
give a lot of mechanism to prevent any misuse, is expressed by the saying: "We
192
+
give a lot of mechanisms to prevent any misuse, is expressed by the saying: "We
193
193
are consenting adults".
194
194
195
195
This doesn't mean that, for example, no properties are considered private, and
196
196
that no proper encapsulation is possible in Python. But, instead of relying on
197
197
concrete walls erected by the developers between their code and other's, the
198
-
Python community prefers to rely on a set of convention indicating that these
198
+
Python community prefers to rely on a set of conventions indicating that these
199
199
elements should not be accessed directly.
200
200
201
201
The main convention for private properties and implementation details is to
202
202
prefix all "internals" with an underscore. If the client code breaks this rule
203
-
and access to these marked elements, any misbehavior or problems encountered if
203
+
and accesses these marked elements, any misbehavior or problems encountered if
204
204
the code is modified is the responsibility of the client code.
205
205
206
206
Using this convention generously is encouraged: any method or property that is
@@ -215,7 +215,7 @@ Returning values
215
215
When a function grows in complexity is not uncommon to use multiple return statements
216
216
inside the function's body. However, in order to keep a clear intent and a sustainable
217
217
readability level, it is preferable to avoid returning meaningful values from many
218
-
output point in the body.
218
+
output points in the body.
219
219
220
220
There are two main cases for returning values in a function: The result of the function
221
221
return when it has been processed normally, and the error cases that indicate a wrong
@@ -227,12 +227,12 @@ as None or False, indicating that the function could not perform correctly might
227
227
case, it is better to return as early as the incorrect context has been detected. It will
228
228
help to flatten the structure of the function: all the code after the return-because-of-error
229
229
statement can assume the condition is met to further compute the function's main result.
230
-
Having multiple such return statement is often necessary.
230
+
Having multiple such return statements is often necessary.
231
231
232
232
However, when a function has multiple main exit points for its normal course, it becomes
233
233
difficult to debug the returned result, and it may be preferable to keep a single exit
234
-
point. This will also help factoring out some code paths, and the multiple exit point
235
-
is a probable indication that such a refactoring is needed.
234
+
point. This will also help factoring out some code paths, and the multiple exit points
235
+
are a probable indication that such a refactoring is needed.
236
236
237
237
.. code-block:: python
238
238
@@ -351,7 +351,7 @@ Take the following code for example::
351
351
return 's' in l
352
352
353
353
Even though both functions look identical, because *lookup_dict* is utilizing the fact that dictionaries in python are hashtables, the lookup performance between the two is very different.
354
-
Python will have to go through each item in the list to find a matching case, which is time consuming. By analysing the hash of the dictionary finding keys in the dict can be done very quickly.
354
+
Python will have to go through each item in the list to find a matching case, which is time consuming. By analysing the hash of the dictionary, finding keys in the dict can be done very quickly.
355
355
For more information see this `StackOverflow <http://stackoverflow.com/questions/513882/python-list-vs-dict-for-look-up-table>`_ page.
356
356
357
357
Zen of Python
@@ -589,9 +589,9 @@ sometimes but is preferably avoided, because of its fragility: a white space
589
589
added to the end of the line, after the backslash, will break the code and may
590
590
have unexpected results.
591
591
592
-
A preferred solution is to use parenthesis around your elements. Left with an
592
+
A preferred solution is to use parentheses around your elements. Left with an
593
593
unclosed parenthesis on an end-of-line the Python interpreter will join the
594
-
next line until the parenthesis is closed. The same behavior holds for curly
594
+
next line until the parentheses are closed. The same behavior holds for curly
0 commit comments