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

structured_data._cant_modify   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 10
dl 0
loc 15
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A cant_modify() 0 9 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