Conditions | 6 |
Total Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 6.3949 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | # -*- coding: utf-8 -*- |
||
57 | 1 | def dict_property(path, anytype): |
|
58 | """ |
||
59 | Creates new strict-typed PROPERTY for classes inherited from :class:`dict` |
||
60 | """ |
||
61 | 1 | def decorator(fn): |
|
62 | |||
63 | 1 | def _get(self): |
|
64 | 1 | v = pydash.get(self.raw, path) |
|
65 | |||
66 | 1 | if v is None: |
|
67 | 1 | return None |
|
68 | |||
69 | 1 | return anytype(v) |
|
70 | |||
71 | 1 | def _set(self, value): |
|
72 | value = fn(self, value) |
||
73 | pydash.set_(self.raw, path, value) |
||
74 | |||
75 | return value |
||
76 | |||
77 | 1 | doc = fn.__doc__ |
|
78 | |||
79 | 1 | if doc is None: |
|
80 | doc = '<AUTO>' |
||
81 | |||
82 | 1 | doc = _handle_auto_doc_for_property( |
|
83 | fn.__doc__, |
||
84 | anytype.__name__ |
||
85 | ) |
||
86 | |||
87 | 1 | p = property(_get, _set, None, doc) |
|
88 | 1 | return p |
|
89 | return decorator |
||
90 |