Passed
Push — master ( af9889...f446f0 )
by Max
01:14
created

structured_data._cant_modify.cant_modify()   A

Complexity

Conditions 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 2
nop 2
1
import inspect
2
3
MISSING = object()
4
5
6
def cant_modify(self, name):
7
    """Prevent attempts to modify an attr of the given name."""
8
    class_repr = repr(self.__class__.__name__)
9
    name_repr = repr(name)
10
    if inspect.getattr_static(self, name, MISSING) is MISSING:
11
        format_msg = "{class_repr} object has no attribute {name_repr}"
12
    else:
13
        format_msg = "{class_repr} object attribute {name_repr} is read-only"
14
    raise AttributeError(format_msg.format(class_repr=class_repr, name_repr=name_repr))
15