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

_is_data()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
c 3
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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