Completed
Push — master ( b1deab...363580 )
by John
17:45 queued 15:34
created

bbarchivist.compat.clock()   A

Complexity

Conditions 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0932

Importance

Changes 0
Metric Value
cc 2
eloc 7
nop 0
dl 0
loc 11
ccs 5
cts 7
cp 0.7143
crap 2.0932
rs 10
c 0
b 0
f 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
0 ignored issues
show
Comprehensibility Bug introduced by
clock is re-defining a name which is already available in the outer-scope (previously defined on line 9).

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:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
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