Skip to content

Commit 643c0b9

Browse files
committed
Merge pull request quantifiedcode#22 from LauritzThaulow/master
Add missing "import whole module" solution
2 parents f722673 + 7588c2e commit 643c0b9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/maintainability/from_module_import_all_used.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,32 @@ The ``import`` statement should be refactored to be more specific about what fun
2424
2525
from math import ceil
2626
27+
Import the whole module
28+
.......................
29+
30+
There are some cases where making the ``import`` statement spesific is not a good solution:
31+
32+
- It may be unpractical or cumbersome to create or maintain the list of objects to be imported from a module
33+
- A direct import would bind to the same name as that of another object (e.g. from asyncio import TimeoutError)
34+
- The module that the object is imported from would provide valuable contextual information if it is right next to the object when it's used.
35+
36+
In these cases, use one of these idioms:
37+
38+
.. code:: python
39+
40+
import math
41+
x = math.ceil(y)
42+
43+
# or
44+
45+
import multiprocessing as mp
46+
pool = mp.pool(8)
47+
48+
2749
References
2850
----------
2951

3052
- PyFlakes - F403
3153
- `Stack Overflow - Importing Modules <http://stackoverflow.com/questions/15145159/importing-modules-how-much-is-too-much>`_
54+
- `Stack Overflow - 'import module' or 'from module import' <http://stackoverflow.com/questions/710551/import-module-or-from-module-import>`_
3255

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