Total Complexity | 2 |
Total Lines | 15 |
Duplicated Lines | 0 % |
Changes | 0 |
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 |