Total Complexity | 6 |
Total Lines | 49 |
Duplicated Lines | 0 % |
Coverage | 84% |
Changes | 0 |
1 | #!/usr/bin/env python3 |
||
2 | 3 | """This module is used for backwards compatibility for older Python 3.""" |
|
3 | |||
4 | 5 | __author__ = "Thurask" |
|
5 | 5 | __license__ = "WTFPL v2" |
|
6 | 5 | __copyright__ = "2015-2018 Thurask" |
|
7 | |||
8 | |||
9 | 5 | def clock(): |
|
10 | """ |
||
11 | Backwards compatibility wrapper for system clock. |
||
12 | """ |
||
13 | 5 | try: |
|
14 | 5 | from time import perf_counter as clock |
|
|
|||
15 | except ImportError: # 3.2 |
||
16 | from time import clock |
||
17 | finally: |
||
18 | 5 | wclock = clock() |
|
19 | 5 | return wclock |
|
20 | |||
21 | |||
22 | 5 | def enum_cpus(): |
|
23 | """ |
||
24 | Backwards compatibility wrapper for CPU count. |
||
25 | """ |
||
26 | 5 | try: |
|
27 | 5 | from os import cpu_count |
|
28 | 1 | except ImportError: # 3.2, 3.3 |
|
29 | 1 | from multiprocessing import cpu_count |
|
30 | finally: |
||
31 | 5 | cpus = cpu_count() |
|
32 | 5 | return cpus |
|
33 | |||
34 | |||
35 | 5 | def where_which(path): |
|
36 | """ |
||
37 | Backwards compatibility wrapper for approximating which/where. |
||
38 | |||
39 | :param path: Path to a file. |
||
40 | :type path: str |
||
41 | """ |
||
42 | 5 | try: |
|
43 | 5 | from shutil import which |
|
44 | except ImportError: # 3.2 |
||
45 | from shutilwhich import which |
||
46 | finally: |
||
47 | 5 | thepath = which(path) |
|
48 | return thepath |
||
49 |
It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior: