Completed
Push — master ( 199334...4dcdc8 )
by Max
02:11
created

get()   A

Complexity

Conditions 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
"""Common operations. Some assume use of _DescriptorInspector."""
2
3
4 6
from .descriptor_inspector import _DescriptorInspector
5
6
7 6
def get(a_map, name):
8
    """Return a _DescriptorInspector around the attribute, or None."""
9 6
    try:
10 6
        value = a_map[name]
11 6
    except KeyError:
12 6
        return None
13
    else:
14 6
        return _DescriptorInspector(value)
15
16
17 6
def delete(dct, name):
18
    """Attempt to delete `name` from `dct`. Raise AttributeError if missing."""
19 6
    try:
20 6
        del dct[name]
21 6
    except KeyError:
22 6
        raise AttributeError(name)
23
24
25 6
def has_get(value):
26
    """Return whether the value is a wrapped getter descriptor."""
27 6
    return value is not None and value.has_get
28
29
30 6
def is_data(value):
31
    """Return whether the value is a wrapped data descriptor."""
32 6
    return value is not None and value.is_data
33
34
35 6
def get_data(dct, name):
36
    """Return the data descriptor associated with `name` in `dct`, if any."""
37 6
    value = get(dct, name)
38 6
    if is_data(value):
39
        return value
40