Skip to content

Commit 73c29a1

Browse files
committed
Proofread files.
1 parent e459776 commit 73c29a1

15 files changed

+38
-35
lines changed

docs/maintainability/duplicate_key_in_dictionary.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ In the module below the ``gmt`` key has been defined twice. When you print out t
2222
.. warning:: The code below is an example of an error. Using this code will create bugs in your programs!
2323

2424
.. code:: python
25-
25+
# first occurrence of 'gmt' below gets silently overridden
2626
time = {"gmt": -08, "hour": 16, "minute": 37, "second": 05, "gmt": -09}
2727
print time # {'second': 05, 'minute': 37, 'hour': 16, 'gmt': -09}
2828
2929
Solutions
3030
---------
3131

32-
Delete duplicate keys
33-
.....................
32+
Delete or rename duplicate keys
33+
...............................
3434

35-
In the modified module below the second, duplicate entry for ``gmt`` has been deleted.
35+
In the modified module below the second, duplicate entry for ``gmt`` has been deleted. Where applicable, another acceptable solution is to give unique names to each of the conflicting items.
3636

3737
.. code:: python
3838

docs/maintainability/from_module_import_all_used.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,22 @@ The following code imports everything from the ``math`` built-in Python module.
2323

2424
.. code:: python
2525
26-
from math import *
26+
from math import * # wildcard import = bad
2727
2828
Solutions
2929
---------
3030

3131
Make the ``import`` statement more specific
3232
...........................................
3333

34-
The ``import`` statement should be refactored to be more specific about what functions or variables it is using from the ``math`` module.
34+
The ``import`` statement should be refactored to be more specific about what functions or variables it is using from the ``math`` module. The modified module below specifies exactly which module member it is using, which happens to be ``ceil`` in this example.
3535

3636
.. code:: python
3737
3838
from math import ceil
3939
40-
4140
References
4241
----------
43-
- `Stack Overflow - Importing Modules <http://stackoverflow.com/questions/15145159/importing-modules-how-much-is-too-much>`_
4442
- PyFlakes - F403
43+
- `Stack Overflow - Importing Modules <http://stackoverflow.com/questions/15145159/importing-modules-how-much-is-too-much>`_
4544

docs/maintainability/import_module_shadowed_by_loop_variable.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Import module from line n shadowed by loop variable
44
Summary
55
-------
66

7-
A loop has defined a variable with the same name as an imported module. This can cause bugs in a module because it overrides the meaning of the module name. Attempting to access module members after the module name has been redefined can result in runtime errors or unintended behavior. The variable name should be renamed to something other than a module name.
7+
A loop has defined a variable with the same name as an imported module. This can cause bugs in a module because it overrides the meaning of the module name. Attempting to access members from the overridden module can result in runtime errors or unintended behavior. The variable name should be renamed to something other than a module name.
88

99
Description
1010
-----------
@@ -17,7 +17,7 @@ Examples
1717
Loop defines variable with same name as imported module
1818
.......................................................
1919

20-
The module below imports the ``os`` Python Standard Library module, which is used for performing miscellaneous tasks related to the current operating system. When ``os.name`` is called, ``os`` still refers to the ``os`` module, so this works fine. But when the for loop creates a variable called ``os`` this overrides the meaning of ``os``. ``os`` now refers to a ``str`` variable. So only members from the ``str`` class are valid on ``os`` now. Any attempt to reference a member from the ``os`` module creates runtime errors. In other words, when the module attempts to reference ``os.name`` in the for loop, it is actually calling ``str.name``. Because the ``str`` data type does not have any member called ``name`` Python raises an error.
20+
The module below imports the ``os`` Python Standard Library module, which is used for performing miscellaneous tasks related to the current operating system. When ``os.name`` is called outside of the loop, ``os`` still refers to the ``os`` module, so this works fine. But notice that the for loop also creates a variable called ``os``. This overrides the meaning of ``os``. ``os`` now refers to a ``str`` variable. So only members from the ``str`` class are valid on ``os`` now. Any attempt to reference a member from the ``os`` *module* creates runtime errors. In other words, when the module attempts to reference ``os.name`` in the for loop, it is actually calling ``str.name``. Because the ``str`` data type does not have any member called ``name`` Python raises an error.
2121

2222
.. warning:: The code below is an example of an error. Using this code will create bugs in your programs!
2323

docs/maintainability/module_imported_but_not_used.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ An imported module is not being used. The ``module imported but not used`` error
1010
Description
1111
-----------
1212

13-
This error typically means that there is an error in the module implementation, so you should review the module under question. There are typically three ways to solve the ``module imported but not used`` error. You can remove the module if it is not needed, check that all sections of the module have been fully implemented (and implement them if not), and check for misspellings of the module name, or any of the public objects available from the module (and fix the mispellings).
13+
This error typically means that there is an error in the module implementation, so you should review the module under question. There are typically three ways to solve the ``module imported but not used`` error. You can remove the module if it is not needed, check that all sections of the module have been fully implemented (and implement them if not), and check for misspellings of the module name or any of the public objects available from the module (and fix the mispellings).
1414

1515
Examples
1616
----------
@@ -35,14 +35,14 @@ Solutions
3535
Remove the module
3636
.................
3737

38-
Upon reviewing the module, the owner of the module decided that the ``math`` module was not needed, so he removed the ``import math`` statement. Because the module is no longer imported the ``module imported but not used`` error is no longer valid.
38+
Upon reviewing the module, the owner of the module decided that the ``math`` module was not needed, so he removed the ``import math`` statement. Because the module is no longer imported the ``module imported but not used`` error is no longer raised.
3939

4040
.. code:: python
4141
4242
# removed import math from here
4343
import time
4444
45-
print "Current UNIX Epoch time:", math.floor(time.time())
45+
print "Current UNIX Epoch time:", time.time()
4646
4747
Use the module
4848
..............

docs/maintainability/not_using_with_to_open_files.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Not using ``with`` to open files
44
Summary
55
-------
66

7-
Use a ``with`` statement to open a filei (e.g. ``with open("file.txt", "r" as f``). This is the standard and safest way to open a file in Python.
7+
Use a ``with`` statement to open a file (e.g. ``with open("file.txt", "r" as f``). This is the standard and safest way to open a file in Python.
88

99
Description
1010
-----------

docs/maintainability/redefining_built-in.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Raised when the function in a user-defined module has the same name as a `Python
99
Description
1010
-----------
1111

12-
When a user-defined function has the same name as a function from a Python Standard Library, the ``Redefining built-in %r`` error is raised, where ``%r`` is the name of the function that is being overloaded with two or more names. Overloading functions is generally a bad programming practice and should be avoided at all costs.
12+
When a user-defined function has the same name as a function from a Python Standard Library, the ``Redefining built-in %r`` error is raised, where ``%r`` is the name of the function that is being overloaded with two or more names. Overloading functions is generally a bad programming practice and should be avoided as much as possible.
1313

1414
Examples
1515
----------

docs/maintainability/redefinition_of_unused_name.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The module below imports the ``json`` module from the Python Standard Library an
2525
2626
import json
2727
28-
json = ['{"first": "John", "last": "Smith"', '"ssn": "613230789"'] # redefinition
28+
json = ['"first": "John"', '"last": "Smith"', '"ssn": "613230789"'] # redefinition
2929
3030
for s in json:
3131
print s
@@ -36,13 +36,13 @@ Solutions
3636
Rename the variable
3737
...................
3838

39-
Often the simplest solution for suppressing the ``redefinition of unused name`` error is to give the objects different, unique names. Because the names are unique, there is no more redefinition taking place, and therefore the error is no longer valid. In the modified module below, the variable storing a list of JSON strings has been changed from ``json`` to ``json_list``.
39+
Often the simplest solution for suppressing the ``redefinition of unused name`` error is to give the objects different, unique names. Because the names are unique, there is no more redefinition taking place, and therefore the error is no longer raised. In the modified module below, the variable storing a list of JSON strings has been changed from ``json`` to ``json_list``.
4040

4141
.. code:: python
4242
4343
import json
4444
45-
json_list = ['{"first": "John", "last": "Smith"', '"ssn": "613230789"'] # ok now, unique name
45+
json_list = ['"first": "John"', '"last": "Smith"', '"ssn": "613230789"'] # ok now
4646
4747
for s in json_list:
4848
print s
@@ -54,7 +54,9 @@ Another way to suppress the ``redefinition of unused name`` error is to remove t
5454

5555
.. code:: python
5656
57-
json = ['{"first": "John", "last": "Smith"', '"ssn": "613230789"'] # ok now, no more redefinition
57+
# deleted import statement, no more overriding of names
58+
59+
json = ['{"first": "John", "last": "Smith"', '"ssn": "613230789"']
5860
5961
for s in json:
6062
print s

docs/maintainability/returning_more_than_one_variable_type_from_function_call.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Examples
2424
Function returns ``None`` upon unsatisfied precondition
2525
.......................................................
2626

27-
In the module below, the function ``get_secret_code()`` returns a secret code when the module calling the function provides the correct password. If the password is incorrect, the function returns ``None``. This leads to hard-to-maintain code, because the caller will have check the type of the return value before proceeding.
27+
In the module below, the function ``get_secret_code()`` returns a secret code when the module calling the function provides the correct password. If the password is incorrect, the function returns ``None``. This leads to hard-to-maintain code, because the caller will have to check the type of the return value before proceeding.
2828

2929
.. warning:: The code below is an example of an error. Using this code will create bugs in your programs!
3030

docs/maintainability/the_loop_may_never_terminate.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The loop may never terminate
44
Summary
55
-------
66

7-
The given loop does not modify anything that impacts the loop condition and does not call ``break``, ``return``, or ``yield`` explicitly, which may lead to an infinite loop.
7+
The given loop does not modify anything that impacts the loop condition and does not call ``break``, ``return``, or ``yield`` explicitly. Therefore, this loop will probably never terminate.
88

99
Description
1010
-----------
@@ -35,7 +35,7 @@ Solutions
3535
Modify the variable that impacts the loop condition
3636
...................................................
3737

38-
In the modified module below, the loop will finish executing as expected, because now the variable ``i`` is incremented by 1 in every iteration of the loop.
38+
In the modified module below, the loop finishes as expected, because now the variable ``i`` is incremented by 1 in every iteration of the loop.
3939

4040
.. code:: python
4141

docs/maintainability/too_many_arguments_for_format_string.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ Too many arguments for format string
44
Summary
55
-------
66

7-
A format string contains more arguments than replacement fields. You can improve the readability and minimize the chance of bugs in the code by updating the format string to have the same number of replacement fields and arguments.
7+
A format string contains more arguments than replacement fields. Fix the format string so that it has the same number of replacement fields as argument strings to minimize bugs and improve readability.
88

99
Description
1010
-----------
1111

12-
Although a format string that contains more arguments than replacement fields will execute just fine, the extra arguments are unused. This reduces code readability and increases the chance of future bugs. Therefore, unless the extra arguments serve a purpose they should be removed.
12+
Although a format string that contains more arguments than replacement fields will execute, the extra arguments reduce code readability and increase the chance of future bugs. Therefore, unless the extra arguments serve a purpose they should be removed.
1313

1414
Examples
1515
----------
@@ -32,17 +32,17 @@ Solutions
3232
Remove extra arguments
3333
......................
3434

35-
Now that the format string contains the same number of replacement fields (two) as arguments (two), the ``too many arguments for format string`` error is suppressed.
35+
The modified module below suppresses the ``too many arguments for format string`` error by fixing the format string to have the same number of replacement fields as arguments.
3636

3737
.. code:: python
3838
39-
numbers = "{:d} {:d}".format(1, 2) # removed the third argument
39+
numbers = "{:d} {:d}".format(1, 2) # removed the extra, third argument
4040
print numbers
4141
4242
Add more replacement fields
4343
...........................
4444

45-
The modified module below adds another replacement field to the string literal to match the number of arguments passed to ``format()``.
45+
The modified module below adds another replacement field to the string literal to match the number of arguments passed to ``format()``. This is another way to fix the format string to have the same number of replacement fields as arguments.
4646

4747
.. code:: python
4848

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy