Conditions | 6 |
Total Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Tests | 16 |
CRAP Score | 6.0073 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | # -*- coding: utf-8 -*- |
||
24 | 1 | def dict_enum_property(path, enumtype): |
|
25 | 1 | def decorator(fn): |
|
26 | |||
27 | 1 | def _get(self): |
|
28 | 1 | v = pydash.get(self.raw, path) |
|
29 | |||
30 | 1 | if v is None: |
|
31 | return None |
||
32 | |||
33 | 1 | return enumtype(v) |
|
34 | |||
35 | 1 | def _set(self, value): |
|
36 | 1 | if isinstance(value, enumtype): |
|
37 | 1 | value = value.value |
|
38 | 1 | value = fn(self, value) |
|
39 | 1 | pydash.set_(self.raw, path, value) |
|
40 | |||
41 | 1 | return enumtype(value) |
|
42 | |||
43 | 1 | doc = _handle_auto_doc_for_property( |
|
44 | fn.__doc__, |
||
45 | '~{mod}.{nm}'.format( |
||
46 | mod=enumtype.__module__, |
||
47 | nm=enumtype.__name__, |
||
48 | ) |
||
49 | ) |
||
50 | |||
51 | 1 | p = property(_get, _set, None, doc) |
|
52 | 1 | return p |
|
53 | 1 | return decorator |
|
54 | |||
90 |